xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::lockFree Namespace Reference

Lock-free algorithms. More...

Classes

class  ConditionVariable
 A notification that can be sent to one or more threads. More...
 
class  LockFreeTraversableMap
 A map that can be traversed without locking. More...
 
class  Pool
 A lock-free pool that manages a number of preallocator memory locations for objects. More...
 
class  Queue
 A lock free queue. More...
 

Typedefs

template<typename Type >
using Atomic = __opaque_atomic_lock_free_type
 An atomic that is always guaranteed to be lock free.
 
template<typename Type >
using PreferLockFreeAtomic = __opaque_atomic_lock_free_type
 An atomic that is lock free if supported.
 

Functions

template<typename Type >
consteval auto isLockFree () noexcept -> bool
 Checks whether an atomic is lock-free.
 

Detailed Description

Lock-free algorithms.

Contains lock-free data types for use in real-time applications.

Typedef Documentation

◆ Atomic

template<typename Type >
using xentara::utils::lockFree::Atomic = typedef __opaque_atomic_lock_free_type

An atomic that is always guaranteed to be lock free.

For types for which std::atomic is lock free, this is a type alias for std::atomic<Type>. On 64-bit platforms that natively do not support lock-free 128 bit atomics, this alias provides access to a custom implementation of 128 bit lock-free atomics.

If a lock-free atomic is not available for Type, this type alias is not available. You can use PreferLockFreeAtomic to select a lock-free type if one is available, but fall back to a locking std::atomic<Type> if not.

Note
When compiling for x64 using GCC or Clang, the compiler option “-mcx16” must be specified in order for 128 bit lock free atomics to be available. Alternatively, you can specify “-march=” with a processor architecture that supports the CMPXCHG16B instruction (“core2” or better).
Include file
#include <xentara/utils/lockFree/Atomic.hpp>
See also
PreferLockFreeAtomic

◆ PreferLockFreeAtomic

template<typename Type >
using xentara::utils::lockFree::PreferLockFreeAtomic = typedef __opaque_atomic_lock_free_type

An atomic that is lock free if supported.

This type alias is the same as Atomic<Type> if a lock-free atomic is available. Otherwise, it falls back to std::atomic<Type>. Use this type alias instead of Atomic if you want a lock-free type if possible, but do not necessarily need one.

Include file
#include <xentara/utils/lockFree/Atomic.hpp>
See also
Atomic

Function Documentation

◆ isLockFree()

template<typename Type >
consteval auto xentara::utils::lockFree::isLockFree ( ) -> bool
noexcept

Checks whether an atomic is lock-free.

On most platforms, this function simply returns Type::is_always_lock_free. On ARMv5T platforms (like Debian armel), however, atomics are only partially lock free, and Type::is_always_lock_free always returns false. On such platforms, this function return true

Template Parameters
AtomicThe type to check. The type must have an interface compatible with std::atomic.
Returns
Returns true if the atomic should be considered lock-free on this platform, or false if it is not lock free.