Library of Assembled Shared Sources
Atomic

Detailed Description

atomic operations and tools for lock-free algorithms

Data Structures

class  lass::util::TaggedPtr< T >
 Pointer with a tag for ABA salvationSome lock-free algorithms suffer from the ABA problem when acting on pointers. More...
 

Functions

template<typename T>
bool lass::util::atomicCompareAndSwap (volatile T &dest, T expectedValue, T newValue)
 Performs the following pseudocode in an atomic way (no other threads can intervene):
 
template<typename T1, typename T2>
bool lass::util::atomicCompareAndSwap (volatile T1 &dest1, T1 expected1, T2 expected2, T1 new1, T2 new2)
 Performs the following pseudocode in an atomic way (no other threads can intervene):
 
template<typename T>
void lass::util::atomicIncrement (volatile T &value)
 Performs the following pseudocode in an atomic way (no other threads can intervene):
 
template<typename T>
void lass::util::atomicDecrement (volatile T &value)
 Performs the following pseudocode in an atomic way (no other threads can intervene):
 
template<typename T>
void lass::util::atomicLock (volatile T &semaphore)
 
template<typename T>
bool lass::util::atomicTryLock (volatile T &semaphore)
 
template<typename T>
void lass::util::atomicUnlock (volatile T &semaphore)
 

Function Documentation

◆ atomicCompareAndSwap() [1/2]

template<typename T>
bool lass::util::atomicCompareAndSwap ( volatile T & dest,
T expectedValue,
T newValue )

Performs the following pseudocode in an atomic way (no other threads can intervene):

if (dest != expectedValue) return false;
dest = newValue;
return true;
Deprecated
Use std::atomic

Definition at line 94 of file atomic.h.

Referenced by atomicLock(), and atomicTryLock().

◆ atomicCompareAndSwap() [2/2]

template<typename T1, typename T2>
bool lass::util::atomicCompareAndSwap ( volatile T1 & dest1,
T1 expected1,
T2 expected2,
T1 new1,
T2 new2 )

Performs the following pseudocode in an atomic way (no other threads can intervene):

if (dest1 != expectedValue1 || *(T2*)(&dest1 + sizeof(T1)) != expected2) return false;
dest1 = new1;
dest2 = new2;
return true;

Does not exist for 64-bit types (there's no 128-bit CAS).

Deprecated
Use std::atomic

Definition at line 117 of file atomic.h.

References LASS_META_ASSERT.

◆ atomicIncrement()

template<typename T>
void lass::util::atomicIncrement ( volatile T & value)

Performs the following pseudocode in an atomic way (no other threads can intervene):

++value;
Deprecated
Use std::atomic

Definition at line 137 of file atomic.h.

Referenced by atomicUnlock().

◆ atomicDecrement()

template<typename T>
void lass::util::atomicDecrement ( volatile T & value)

Performs the following pseudocode in an atomic way (no other threads can intervene):

--value;
Deprecated
Use std::atomic

Definition at line 155 of file atomic.h.

◆ atomicLock()

template<typename T>
void lass::util::atomicLock ( volatile T & semaphore)
Deprecated
Use std::atomic

Definition at line 168 of file atomic.h.

References atomicCompareAndSwap().

◆ atomicTryLock()

template<typename T>
bool lass::util::atomicTryLock ( volatile T & semaphore)
Deprecated
Use std::atomic

Definition at line 186 of file atomic.h.

References atomicCompareAndSwap().

◆ atomicUnlock()

template<typename T>
void lass::util::atomicUnlock ( volatile T & semaphore)
Deprecated
Use std::atomic

Definition at line 209 of file atomic.h.

References atomicIncrement().