cds
2.3.2
|
Marked pointer. More...
#include <cds/details/marked_ptr.h>
Public Types | |
typedef T | value_type |
type of value the class points to | |
typedef T * | pointer_type |
type of pointer | |
Public Member Functions | |
constexpr | marked_ptr () noexcept |
Constructs null marked pointer. The flag is cleared. | |
constexpr | marked_ptr (value_type *ptr) noexcept |
Constructs marked pointer with ptr value. The least bit(s) of ptr is the flag. | |
marked_ptr (value_type *ptr, int nMask) noexcept | |
Constructs marked pointer with ptr value and nMask flag. More... | |
marked_ptr (marked_ptr const &src) noexcept=default | |
Copy constructor. | |
marked_ptr & | operator= (marked_ptr const &p) noexcept=default |
Copy-assignment operator. | |
value_type * | ptr () const noexcept |
Returns the pointer without mark bits (real pointer) const version. | |
value_type * | all () const noexcept |
Returns the pointer and bits together. | |
uintptr_t | bits () const noexcept |
Returns the least bits of pointer according to Bitmask template argument of the class. | |
value_type * | operator-> () const noexcept |
Analogue for ptr. | |
marked_ptr | operator= (T *p) noexcept |
Assignment operator sets markup bits to zero. | |
marked_ptr & | operator|= (int nBits) noexcept |
Set LSB bits as bits() | nBits | |
marked_ptr & | operator&= (int nBits) noexcept |
Set LSB bits as bits() & nBits | |
marked_ptr & | operator^= (int nBits) noexcept |
Set LSB bits as bits() ^ nBits | |
Static Public Attributes | |
static constexpr const uintptr_t | bitmask = Bitmask |
bitfield bitmask | |
static constexpr const uintptr_t | pointer_bitmask = ~bitmask |
pointer bitmask | |
Private Attributes | |
T * | m_ptr |
pointer and its mark bits | |
Friends | |
marked_ptr | operator| (marked_ptr p, int nBits) noexcept |
Returns p |= nBits | |
marked_ptr | operator| (int nBits, marked_ptr p) noexcept |
Returns p |= nBits | |
marked_ptr | operator& (marked_ptr p, int nBits) noexcept |
Returns p &= nBits | |
marked_ptr | operator& (int nBits, marked_ptr p) noexcept |
Returns p &= nBits | |
marked_ptr | operator^ (marked_ptr p, int nBits) noexcept |
Returns p ^= nBits | |
marked_ptr | operator^ (int nBits, marked_ptr p) noexcept |
Returns p ^= nBits | |
marked_ptr | operator~ (marked_ptr p) noexcept |
Inverts LSBs of pointer p . | |
bool | operator== (marked_ptr p1, marked_ptr p2) noexcept |
Comparing two marked pointer including its mark bits. | |
bool | operator== (marked_ptr p1, value_type const *p2) noexcept |
Comparing marked pointer and raw pointer, mark bits of p1 is ignored. | |
bool | operator== (value_type const *p1, marked_ptr p2) noexcept |
Comparing marked pointer and raw pointer, mark bits of p2 is ignored. | |
bool | operator!= (marked_ptr p1, marked_ptr p2) noexcept |
Comparing two marked pointer including its mark bits. | |
bool | operator!= (marked_ptr p1, value_type const *p2) noexcept |
Comparing marked pointer and raw pointer, mark bits of p1 is ignored. | |
bool | operator!= (value_type const *p1, marked_ptr p2) noexcept |
Comparing marked pointer and raw pointer, mark bits of p2 is ignored. | |
Marked pointer.
On the modern architectures, the default data alignment is 4 (for 32bit) or 8 byte for 64bit. Therefore, the least 2 or 3 bits of the pointer is always zero and can be used as a bitfield to store logical flags. This trick is widely used in lock-free programming to operate with the pointer and its flags atomically.
Template parameters:
|
inlinenoexcept |
Constructs marked pointer with ptr
value and nMask
flag.
The nMask
argument defines the OR-bits