ThreadSafeRef< REFERENCE > Class Template Reference Data Structures

#include <threadsaferef.h>

Inheritance diagram for ThreadSafeRef< REFERENCE >:

详细描述

template<typename REFERENCE>
class maxon::ThreadSafeRef< REFERENCE >

Template for safe access to BaseRef from multiple threads. This comes at the cost of extra atomic operations and will cause high contention if used thoughtless.

ThreadSafeRef<SampleClassRef> g_global;

// consumer thread SampleClassRef now = g_global;

// producer thread SampleClassRef newObject = CreateSomething(); g_global = newObject;

注意
If there is high contention a queue will perform much better (no matter if you use a job queue or a MPMC queue to store the objects only).
Template Parameters
REFERENCE Type of the reference that will be stored thread-safe.

公共成员函数

  ThreadSafeRef ()
  ThreadSafeRef (const REFERENCE &strongReference)
  ThreadSafeRef (const ThreadSafeRef & src )
  ThreadSafeRef ( ThreadSafeRef && src )
  ~ThreadSafeRef ()
ThreadSafeRef operator= (const REFERENCE &strongReference)
Bool   TryCompareAndSwap (const REFERENCE &strongReference, const REFERENCE &compare)
ThreadSafeRef operator= (const ThreadSafeRef & src )
ThreadSafeRef operator= (std::nullptr_t)
ThreadSafeRef operator= ( ThreadSafeRef && src )
REFERENCE  Get () const
  operator REFERENCE () const

Private Types

using  DereferencedPtr = typename REFERENCE::ReferencedType *

Additional Inherited Members

-  Protected Member Functions inherited from ThreadSafePtr< REFERENCE::ReferencedType * >
MAXON_IMPLICIT   ThreadSafePtr (REFERENCE::ReferencedType * src=nullptr)
  ~ThreadSafePtr ()
REFERENCE::ReferencedType *  AcquirePtr () const
void  ReleasePtr (REFERENCE::ReferencedType * ptr) const
REFERENCE::ReferencedType *  ChangePtr (REFERENCE::ReferencedType * ptr) const
Bool   TryCompareAndSwapPtr (REFERENCE::ReferencedType * ptr, REFERENCE::ReferencedType * compare) const
REFERENCE::ReferencedType *  AttemptAcquirePtr () const
-  Protected Attributes inherited from ThreadSafePtr< REFERENCE::ReferencedType * >
AtomicUInt   _ptr

Member Typedef Documentation

◆  DereferencedPtr

using DereferencedPtr = typename REFERENCE::ReferencedType*
private

构造函数 & 析构函数文档编制

◆  ThreadSafeRef() [1/4]

ThreadSafeRef ( )

◆  ThreadSafeRef() [2/4]

ThreadSafeRef ( const REFERENCE &  strongReference )
explicit
参数
[in] strongReference BaseRef with strong reference to an object.

◆  ThreadSafeRef() [3/4]

ThreadSafeRef ( const ThreadSafeRef < REFERENCE > &  src )

Copy constructs a thread safe pointer. THREADSAFE.

参数
[in] src Source thread safe pointer.

◆  ThreadSafeRef() [4/4]

ThreadSafeRef ( ThreadSafeRef < REFERENCE > &&  src )

Moves a thread safe pointer. THREADSAFE.

参数
[in] src Source thread safe pointer.

◆  ~ThreadSafeRef()

~ ThreadSafeRef ( )

THREADSAFE.

成员函数文档编制

◆  operator=() [1/4]

ThreadSafeRef & operator= ( const REFERENCE &  strongReference )

Adds a strong reference. THREADSAFE.

参数
[in] strongReference BaseRef with strong reference to an object.
返回
*this.

◆  TryCompareAndSwap()

Bool TryCompareAndSwap ( const REFERENCE &  strongReference ,
const REFERENCE &  compare  
)

Atomic compare and swap of the reference. THREADSAFE.

参数
[in] strongReference BaseRef with strong reference to an object.
[in] compare Old BaseRef to compare with current value.
返回
True if the reference was exchanged.

◆  operator=() [2/4]

ThreadSafeRef & operator= ( const ThreadSafeRef < REFERENCE > &  src )

Copies a thread safe pointer.

参数
[in] src Source thread safe pointer.
返回
*this.

◆  operator=() [3/4]

ThreadSafeRef & operator= ( std::nullptr_t  )

Resets the thread safe pointer.

返回
*this.

◆  operator=() [4/4]

ThreadSafeRef & operator= ( ThreadSafeRef < REFERENCE > &&  src )

Moves a thread safe pointer.

参数
[in] src Source thread safe pointer.
返回
*this.

◆  Get()

REFERENCE Get ( ) const

Constructs a new BaseRef with a strong reference. THREADSAFE.

返回
BaseRef with a strong reference.

◆  operator REFERENCE()

operator REFERENCE ( ) const

Constructs a new BaseRef with a strong reference. THREADSAFE.

返回
BaseRef with a strong reference.