An atomic reference count object. More...
#include <sharedptr.h>
Public Member Functions | |
| RefCount () | |
| Constructs a reference count initialized to 1. | |
| RefCount (const RefCount &o) | |
| Copy constructor resets the reference count to 1 for the new object. | |
| RefCount & | operator= (const RefCount &) |
| Copy assignment resets the reference count to 1. | |
| void | inc () |
| Atomically increments the reference count. | |
| bool | dec () |
| Atomically decrements the reference count. | |
| int | value () const |
| Returns the current reference count value. | |
| bool | isImmortal () const |
| Returns true if this refcount is immortal (will never reach zero). | |
| void | setImmortal () |
| Marks this refcount as immortal. inc/dec become no-ops. | |
Static Public Attributes | |
| static constexpr int | Immortal = 0x40000000 |
| Threshold at or above which the refcount is considered immortal. | |
An atomic reference count object.
Since it's atomic, operations are guaranteed to be consistent across threads. This also means there's going to be an increased cost over a simple reference count. However, this is generally still faster than any locking semantics that would be required to syncronize data between threads.
|
inline |
Atomically decrements the reference count.
Returns false for immortal objects (never deleted).
|
inline |
Atomically increments the reference count.
No-op for immortal objects. Uses relaxed memory ordering since only the atomic increment itself needs to be consistent.