Skip to content
Brass Orrery

Orrery Terrain · OrreryTerrainCore module · class

Native::

TAtomicSharedPtr

A std::shared_ptr<T> behind a std::mutex, with the member names and call shapes of std::atomic<std::shared_ptr<T>>.

Declaration

class TAtomicSharedPtr
Header
#include "Native/AtomicSharedPtr.h"
Module
PublicDependencyModuleNames.Add("OrreryTerrainCore"); in your module’s Build.cs.
Stability
Stable: changes within a major version only add.
Thread
load: any thread.

Description

Tier 1, standard library only. libc++ has no std::atomic<std::shared_ptr<T>> specialisation (MSVC's STL has one), and the std::atomic_load / std::atomic_store overloads for shared_ptr are deprecated in C++20, so Tier 1 code that publishes a shared pointer across threads uses this wrapper instead. The cost model is MSVC's own: its atomic<shared_ptr> also takes an internal lock on every load and store.

load copies the pointer under the lock (a reference-count increment). store and exchange swap it under the lock, and the previous value is released only after the lock is dropped, so a pointee's destructor never runs while the lock is held. The mutex is a leaf lock: nothing is acquired while it is held, and no user code runs under it.

The std::memory_order arguments are accepted for source compatibility and ignored: every operation is sequentially consistent, since all of them are ordered by the one mutex.

Note.

load: any thread. store and exchange: any thread; the terrain publishes from the game thread only. Never blocks on IO, never allocates under the lock.

Functions

  • TAtomicSharedPtr (3 overloads)
  • operator=
  • load

    A copy of the current pointer, which keeps the pointee alive.

  • store

    Replace the pointer; the previous pointee, if this held its last reference, is destroyed after the lock is dropped.

  • exchange

    Replace the pointer and return the previous one.

  • is_lock_free

    Always false: loads and stores take a lock.

Type aliases

  • FValuestd::shared_ptr<T>