Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_atomic_ptr.h File Reference
#include "vl_atomic.h"
+ Include dependency graph for vl_atomic_ptr.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  vl_tagged_ptr
 A Tagged Pointer structure for use with Atomic, lock-free algorithms. More...
 

Macros

#define vlAtomicPtrInit(atPtr, valPtr)   vlAtomicInit((atPtr), valPtr);
 
#define vlAtomicPtrCompareExchangeStrong(atPtr, atPtrExpected, valPtr)    vlAtomicPtrCompareExchangeStrongExplicit(atPtr, atPtrExpected, valPtr, VL_MEMORY_ORDER_SEQ_CST, VL_MEMORY_ORDER_SEQ_CST)
 Convenience macro for strong atomic tagged pointer CAS with sequential consistency.
 
#define vlAtomicPtrCompareExchangeWeak(atPtr, atPtrExpected, valPtr)    vlAtomicPtrCompareExchangeWeakExplicit(atPtr, atPtrExpected, valPtr, VL_MEMORY_ORDER_SEQ_CST, VL_MEMORY_ORDER_SEQ_CST)
 Convenience macro for weak atomic tagged pointer CAS with sequential consistency.
 

Typedefs

typedef VL_ATOMIC vl_tagged_ptr vl_atomic_ptr
 Atomic variant of vl_tagged_ptr.
 

Variables

const vl_tagged_ptr VL_TAGPTR_NULL
 Default initialization value for tagged/atomic pointers.
 

Data Structure Documentation

◆ vl_tagged_ptr

struct vl_tagged_ptr

A Tagged Pointer structure for use with Atomic, lock-free algorithms.

Using extra state, a tagged pointer helps to distinguish atomic changes to memory to eliminate the ABA problem. The pointer tag is a counter that is incremented with write operation. The tag occupies as many bytes as the native system pointer type.

See also
https://en.wikipedia.org/wiki/ABA_problem

This structure may depend on 128-bit Compare-and-swap on modern platforms to achieve proper atomicity. (Double-width compare-and-swap, aka DWCAS, hardware instruction or similar). Depending on the platform and compiler, it may require an implicit lock.

+ Collaboration diagram for vl_tagged_ptr:
Data Fields
vl_uintptr_t ptr
vl_ularge_t tag

Macro Definition Documentation

◆ vlAtomicPtrCompareExchangeStrong

#define vlAtomicPtrCompareExchangeStrong ( atPtr,
atPtrExpected,
valPtr )    vlAtomicPtrCompareExchangeStrongExplicit(atPtr, atPtrExpected, valPtr, VL_MEMORY_ORDER_SEQ_CST, VL_MEMORY_ORDER_SEQ_CST)

Convenience macro for strong atomic tagged pointer CAS with sequential consistency.

Parameters
atPtrPointer to atomic tagged pointer.
atPtrExpectedExpected pointer/tag (updated on failure).
valPtrNew pointer value.
Returns
VL_TRUE if successful, VL_FALSE otherwise.
See also
vlAtomicPtrCompareExchangeStrongExplicit

◆ vlAtomicPtrCompareExchangeWeak

#define vlAtomicPtrCompareExchangeWeak ( atPtr,
atPtrExpected,
valPtr )    vlAtomicPtrCompareExchangeWeakExplicit(atPtr, atPtrExpected, valPtr, VL_MEMORY_ORDER_SEQ_CST, VL_MEMORY_ORDER_SEQ_CST)

Convenience macro for weak atomic tagged pointer CAS with sequential consistency.

Parameters
atPtrPointer to atomic tagged pointer.
atPtrExpectedExpected pointer/tag (updated on failure).
valPtrNew pointer value.
Returns
VL_TRUE if successful, VL_FALSE otherwise.
See also
vlAtomicPtrCompareExchangeWeakExplicit

◆ vlAtomicPtrInit

#define vlAtomicPtrInit ( atPtr,
valPtr )   vlAtomicInit((atPtr), valPtr);

Typedef Documentation

◆ vl_atomic_ptr

Atomic variant of vl_tagged_ptr.

A Tagged Pointer structure for use with Atomic, lock-free algorithms.

Using extra state, a tagged pointer helps to distinguish atomic changes to memory to eliminate the ABA problem. The pointer tag is a counter that is incremented with write operation. The tag occupies as many bytes as the native system pointer type.

See also
https://en.wikipedia.org/wiki/ABA_problem

This structure may depend on 128-bit Compare-and-swap on modern platforms to achieve proper atomicity. (Double-width compare-and-swap, aka DWCAS, hardware instruction or similar). Depending on the platform and compiler, it may require an implicit lock.

Variable Documentation

◆ VL_TAGPTR_NULL

const vl_tagged_ptr VL_TAGPTR_NULL
extern

Default initialization value for tagged/atomic pointers.

ptr = NULL;
tag = 0;