Evo C++ Library v0.5.1
Classes | Typedefs | Functions | Variables
EvoThread

Evo threads and atomics. More...

Classes

class  Atomic< T >
 Atomic integer type. More...
 
struct  AtomicFlag
 Atomic signalling flag. More...
 
class  AtomicPtr< T >
 Atomic dumb pointer to single object. More...
 
class  AtomicPtr< T[]>
 Atomic dumb pointer to array. More...
 
struct  Condition
 Condition object for thread synchronization. More...
 
struct  Mutex
 Mutex for thread synchronization. More...
 
struct  MutexInert
 Inert mutex used to disable thread synchronization. More...
 
struct  MutexRW
 Read/Write Mutex for thread synchronization. More...
 
struct  Singleton< T >
 Manages a singleton instance for given type. More...
 
struct  SleepLock
 Variation of SpinLock for thread synchronization using sleep-wait. More...
 
struct  SmartLock< T >
 Smart locking for synchronization. More...
 
struct  SmartLockInert< T >
 Inert lock that doesn't do anything. More...
 
struct  SmartLockRead< T >
 Smart read-locking for synchronization. More...
 
struct  SmartSleepLock< T >
 Smart sleep-locking for synchronization. More...
 
struct  SpinLock
 Spin-lock for thread synchronization. More...
 
struct  SysMutex
 
struct  SysThread
 
struct  Thread
 Manages a single thread of execution. More...
 
struct  ThreadClass
 Base class for managing a single class-based thread of execution. More...
 
struct  ThreadGroup< T, S, M >
 Manages a group of threads with shared state. More...
 
struct  ThreadScope< T >
 Creates a single thread of execution in given scope. More...
 
struct  ThreadScope< Thread >
 Creates a single thread of execution in given scope. More...
 

Typedefs

typedef Atomic< int > AtomicInt
 Atomic signed int. More...
 
typedef Atomic< int32 > AtomicInt32
 Atomic 32-bit signed int. More...
 
typedef Atomic< int64 > AtomicInt64
 Atomic 64-bit signed int. More...
 
typedef Atomic< long > AtomicLong
 Atomic signed long. More...
 
typedef Atomic< longl > AtomicLongL
 Atomic signed long long. More...
 
typedef Atomic< uint > AtomicUInt
 Atomic unsigned int. More...
 
typedef Atomic< uint32 > AtomicUInt32
 Atomic 32-bit unsigned int. More...
 
typedef Atomic< uint64 > AtomicUInt64
 Atomic 64-bit unsigned int. More...
 
typedef Atomic< ulong > AtomicULong
 Atomic unsigned long. More...
 
typedef Atomic< ulongl > AtomicULongL
 Atomic unsigned long long. More...
 
typedef PtrBase< T, Atomic< T * > > Base
 Base type. More...
 
typedef PtrBase< T, Atomic< T * > > Base
 Base type. More...
 
typedef pthread_t Handle
 
typedef pthread_mutex_t Handle
 Mutex handle type. More...
 
typedef SmartLockInert< MutexInertLock
 Lock object type (inert) – see SmartLockInert. More...
 
typedef SmartLockInert< MutexInertLockRead
 Read Lock object type (inert) – see SmartLockInert. More...
 
typedef SmartLockInert< MutexInertLockWrite
 Write Lock object type (inert) – see SmartLockInert. More...
 
typedef std::memory_order MemOrder
 Atomic memory order (fence) type. More...
 
typedef PtrBase< T > PtrBaseT
 Managed pointer base type. More...
 
typedef PtrBase< T > PtrBaseT
 Managed pointer base type. More...
 
typedef void *(* RunFunc) (void *)
 
typedef SmartLockInert< MutexInertSleepLock
 Sleep-Lock object type (inert) – see SmartLockInert. More...
 
typedef Atomic< T > This
 This type. More...
 
typedef AtomicPtr< T > This
 This type. More...
 
typedef AtomicPtr< T[]> This
 This type. More...
 

Functions

 Atomic ()
 Constructor, initializes with 0. More...
 
 Atomic (T num)
 Constructor. More...
 
 AtomicFlag ()
 
 AtomicPtr ()
 Default constructor sets as NULL. More...
 
 AtomicPtr (T *ptr)
 Constructor. More...
 
 AtomicPtr (const T *ptr)
 Constructor. More...
 
 AtomicPtr (const This &src)
 Copy constructor. More...
 
 AtomicPtr (const Base &src)
 Copy constructor to reference pointer. More...
 
 AtomicPtr (const PtrBaseT &src)
 Copy constructor to reference pointer. More...
 
 AtomicPtr ()
 Default constructor sets as NULL. More...
 
 AtomicPtr (T *ptr)
 Constructor. More...
 
 AtomicPtr (const T *ptr)
 Constructor. More...
 
 AtomicPtr (const This &src)
 Copy constructor. More...
 
 AtomicPtr (const Base &src)
 Copy constructor to reference pointer. More...
 
 AtomicPtr (const PtrBaseT &src)
 Copy constructor to reference pointer. More...
 
 SmartLock (T &object, bool lock=true)
 Constructor. More...
 
 SmartLockInert (T &)
 Constructor – arg is ignored. More...
 
 SmartLockInert (T &, bool)
 Constructor – args are ignored. More...
 
 SmartLockInert (T &, ulong)
 Constructor – args are ignored. More...
 
 SmartLockRead (T &object, bool lock=true)
 Constructor. More...
 
 SmartSleepLock (T &object, ulong sleep_ms=1)
 Constructor. More...
 
 SysMutex ()
 Constructor. More...
 
 SysThread ()
 
 ~SmartLock ()
 Destructor, unlocks if locked here. More...
 
 ~SmartLockRead ()
 Destructor, unlocks if locked here. More...
 
 ~SmartSleepLock ()
 Destructor, unlocks if locked here. More...
 
 ~SysMutex ()
 Destructor. More...
 
 ~SysThread ()
 
void clear (MemOrder mem_order=std::memory_order_seq_cst)
 Clear flag (set to false). More...
 
Thisclear ()
 Clear pointer, setting as null. More...
 
Thisclear ()
 Clear pointer, setting as null. More...
 
bool compare_set (T cmpval, T newval, MemOrder mem_order_success=std::memory_order_seq_cst, MemOrder mem_order_failure=std::memory_order_acquire)
 Compare and set, storing new value if comparison matches. More...
 
void detach ()
 
T * detach ()
 Detach and return pointer. More...
 
T * detach ()
 Detach and return pointer. More...
 
exchange (T num, MemOrder mem_order=std::memory_order_seq_cst)
 Exchange current value with new value. More...
 
fetch_add (T num, MemOrder mem_order=std::memory_order_seq_cst)
 Add number to value and return the previous value. More...
 
fetch_and (T num, MemOrder mem_order=std::memory_order_seq_cst)
 Bitwise AND with value and return the previous value. More...
 
fetch_or (T num, MemOrder mem_order=std::memory_order_seq_cst)
 Bitwise OR with value and return the previous value. More...
 
fetch_sub (T num, MemOrder mem_order=std::memory_order_seq_cst)
 Subtract number to value and return the previous value. More...
 
fetch_xor (T num, MemOrder mem_order=std::memory_order_seq_cst)
 Bitwise XOR with value and return the previous value. More...
 
ulong get_tid ()
 Get current thread ID from system. More...
 
static ulong id ()
 
bool join ()
 
load (MemOrder mem_order=std::memory_order_seq_cst) const
 Load and return current value. More...
 
SmartLockInertlock ()
 Lock object (no-op). More...
 
SmartLocklock ()
 Lock object, if not already locked by this. More...
 
SmartLockInertlock (ulong)
 Lock object (no-op). More...
 
void lock ()
 Lock object (no-op). More...
 
SmartLockReadlock ()
 Read-Lock object, if not already locked by this. More...
 
SmartSleepLocklock (ulong sleep_ms=1)
 Lock object, if not already locked by this. More...
 
void lock ()
 Spin-lock flag. More...
 
void lock ()
 Lock mutex. More...
 
void lock_read ()
 Read-lock object (no-op). More...
 
operator &= (T num)
 Bitwise AND value and return new value. More...
 
 operator T () const
 Implicit conversion to integer type. More...
 
bool operator! () const
 Negation operator checks if NULL/false (0). More...
 
bool operator!= (const This &num) const
 Compare whether current value is not equal to number. More...
 
bool operator!= (T num) const
 Compare whether current value is not equal to number. More...
 
bool operator!= (const PtrBaseT &ptr) const
 Inequality operator. More...
 
bool operator!= (const PtrBaseT &ptr) const
 Inequality operator. More...
 
template<class T >
bool operator!= (const PtrBase< T > &ptr1, const PtrBase< T, Atomic< T *> > &ptr2)
 Inequality operator for managed pointer base and atomic pointer base. More...
 
operator++ ()
 Increment value and return new value. More...
 
operator++ (int)
 Increment value and return previous value. More...
 
T * operator++ ()
 Prefix increment operator. More...
 
T * operator++ (int)
 Prefix increment operator. More...
 
T * operator++ ()
 Prefix increment operator. More...
 
T * operator++ (int)
 Prefix increment operator. More...
 
operator+= (T num)
 Increment value and return new value. More...
 
Thisoperator+= (int count)
 Increment by count operator. More...
 
Thisoperator+= (int count)
 Increment by count operator. More...
 
operator-- ()
 Decrement value and return new value. More...
 
operator-- (int)
 Decrement value and return previous value. More...
 
T * operator-- ()
 Prefix decrement operator. More...
 
T * operator-- (int)
 Postfix decrement operator. More...
 
T * operator-- ()
 Prefix decrement operator. More...
 
T * operator-- (int)
 Postfix decrement operator. More...
 
operator-= (T num)
 Decrement value and return new value. More...
 
Thisoperator-= (int count)
 Decrement by count operator. More...
 
Thisoperator-= (int count)
 Decrement by count operator. More...
 
const T operator-> () const
 Member access operator (const). More...
 
operator-> ()
 Member access operator. More...
 
bool operator< (T num) const
 Compare whether current value is less than number. More...
 
bool operator< (const PtrBaseT &ptr) const
 Less-than operator. More...
 
bool operator< (const PtrBaseT &ptr) const
 Less-than operator. More...
 
template<class T >
bool operator< (const PtrBase< T > &ptr1, const PtrBase< T, Atomic< T *> > &ptr2)
 Less-than operator for managed pointer base and atomic pointer base. More...
 
bool operator<= (T num) const
 Compare whether current value is less than or equal to number. More...
 
bool operator<= (const PtrBaseT &ptr) const
 Less-than-or-equals operator. More...
 
bool operator<= (const PtrBaseT &ptr) const
 Less-than-or-equals operator. More...
 
template<class T >
bool operator<= (const PtrBase< T > &ptr1, const PtrBase< T, Atomic< T *> > &ptr2)
 Less-than-or-equals operator for managed pointer base and atomic pointer base. More...
 
Thisoperator= (T num)
 Store new value. More...
 
Thisoperator= (const This &src)
 Copy/Assignment operator. More...
 
Thisoperator= (const Base &src)
 Assignment operator to reference pointer. More...
 
Thisoperator= (const PtrBaseT &src)
 Assignment operator to reference pointer. More...
 
Thisoperator= (T *ptr)
 Assignment operator for raw pointer. More...
 
Thisoperator= (const T *ptr)
 Assignment operator for raw pointer. More...
 
Thisoperator= (const This &src)
 Copy/Assignment operator. More...
 
Thisoperator= (const Base &src)
 Assignment operator to reference pointer. More...
 
Thisoperator= (const PtrBaseT &src)
 Assignment operator to reference pointer. More...
 
Thisoperator= (T *ptr)
 Assignment operator for raw pointer. More...
 
Thisoperator= (const T *ptr)
 Assignment operator for raw pointer. More...
 
bool operator== (const This &num) const
 Compare whether current value is equal to number. More...
 
bool operator== (T num) const
 Compare whether current value is equal to number. More...
 
bool operator== (const PtrBaseT &ptr) const
 Equality operator. More...
 
bool operator== (const PtrBaseT &ptr) const
 Equality operator. More...
 
template<class T >
bool operator== (const PtrBase< T > &ptr1, const PtrBase< T, Atomic< T *> > &ptr2)
 Equality operator for managed pointer base and atomic pointer base. More...
 
bool operator> (T num) const
 Compare whether current value is greater than number. More...
 
bool operator> (const PtrBaseT &ptr) const
 Greater-than operator. More...
 
bool operator> (const PtrBaseT &ptr) const
 Greater-than operator. More...
 
template<class T >
bool operator> (const PtrBase< T > &ptr1, const PtrBase< T, Atomic< T *> > &ptr2)
 Greater-than operator for managed pointer base and atomic pointer base. More...
 
bool operator>= (T num) const
 Compare whether current value is greater than or equal to number. More...
 
bool operator>= (const PtrBaseT &ptr) const
 Greater-than-or-equals operator. More...
 
bool operator>= (const PtrBaseT &ptr) const
 Greater-than-or-equals operator. More...
 
template<class T >
bool operator>= (const PtrBase< T > &ptr1, const PtrBase< T, Atomic< T *> > &ptr2)
 Greater-than-or-equals operator for managed pointer base and atomic pointer base. More...
 
operator^= (T num)
 Bitwise XOR value and return new value. More...
 
operator|= (T num)
 Bitwise OR value and return new value. More...
 
void sleeplock (ulong)
 Lock object (no-op). More...
 
void sleeplock (ulong ms=1)
 Spin-lock flag with a sleep. More...
 
Error start (RunFunc run_func, void *run_ptr)
 
void store (T num, MemOrder mem_order=std::memory_order_seq_cst)
 Store new value. More...
 
bool test_and_set (MemOrder mem_order=std::memory_order_seq_cst)
 Atomically set flag (to true) and return the previous value. More...
 
bool trylock ()
 Try to lock (no-op). More...
 
bool trylock ()
 Try to lock mutex without blocking. More...
 
bool trylock (ulong timeout_ms)
 Try to lock mutex with a timeout. More...
 
bool trylock_read ()
 Try to read-lock (no-op). More...
 
SmartLockInertunlock ()
 Unlock object (no-op). More...
 
SmartLockunlock ()
 Unlock object, if locked by this. More...
 
void unlock ()
 Unlock object (no-op). More...
 
SmartLockReadunlock ()
 Read-Unlock object, if locked by this. More...
 
SmartSleepLockunlock ()
 Unlock object, if locked by this. More...
 
void unlock ()
 Spin-unlock flag. More...
 
void unlock ()
 Unlock mutex. More...
 
void unlock_read ()
 Un-read-lock object (no-op). More...
 
static void yield ()
 

Variables

bool attached
 
Handle handle
 
Handle handle
 Mutex handle – do not modify. More...
 
bool locked_
 Whether object is locked by this. More...
 
bool locked_
 Whether object is read-locked by this. More...
 
bool locked_
 Whether object is read-locked by this. More...
 
T & object_
 Synchronization object to lock. More...
 
T & object_
 Synchronization object to read-lock. More...
 
T & object_
 Synchronization object to read-lock. More...
 

Detailed Description

Evo threads and atomics.

Typedef Documentation

◆ AtomicInt

typedef Atomic<int> AtomicInt

Atomic signed int.

◆ AtomicInt32

typedef Atomic<int32> AtomicInt32

Atomic 32-bit signed int.

◆ AtomicInt64

typedef Atomic<int64> AtomicInt64

Atomic 64-bit signed int.

◆ AtomicLong

typedef Atomic<long> AtomicLong

Atomic signed long.

◆ AtomicLongL

typedef Atomic<longl> AtomicLongL

Atomic signed long long.

◆ AtomicUInt

typedef Atomic<uint> AtomicUInt

Atomic unsigned int.

◆ AtomicUInt32

typedef Atomic<uint32> AtomicUInt32

Atomic 32-bit unsigned int.

◆ AtomicUInt64

typedef Atomic<uint64> AtomicUInt64

Atomic 64-bit unsigned int.

◆ AtomicULong

typedef Atomic<ulong> AtomicULong

Atomic unsigned long.

◆ AtomicULongL

typedef Atomic<ulongl> AtomicULongL

Atomic unsigned long long.

◆ Base [1/2]

typedef PtrBase<T, Atomic<T*> > Base

Base type.

◆ Base [2/2]

typedef PtrBase<T, Atomic<T*> > Base

Base type.

◆ Handle [1/2]

typedef pthread_t Handle

◆ Handle [2/2]

typedef pthread_mutex_t Handle

Mutex handle type.

◆ Lock

Lock object type (inert) – see SmartLockInert.

◆ LockRead

Read Lock object type (inert) – see SmartLockInert.

◆ LockWrite

Write Lock object type (inert) – see SmartLockInert.

◆ MemOrder

typedef std::memory_order MemOrder

Atomic memory order (fence) type.

  • This is passed to an atomic function to specify memory ordering (fence) level
  • Values map to C++11 memory_order values – see: std::memory_order and C++11 memory model:
    • EVO_ATOMIC_RELAXED: Relaxed memory ordering, used between start/end memory barriers – std::memory_order_relaxed
    • EVO_ATOMIC_CONSUME: Start "consume" memory ordering barrier, usually followed by a matching "release" barrier – std::memory_order_consume
    • EVO_ATOMIC_ACQUIRE: Start "acquire" memory ordering barrier, usually followed by a matching "release" barrier – std::memory_order_acquire
    • EVO_ATOMIC_RELEASE: Release (end) memory ordering barrier started with "consume" or "acquire" barrier – std::memory_order_release
    • EVO_ATOMIC_ACQ_REL: Combined acquire/release fence – std::memory_order_acq_rel
    • EVO_ATOMIC_SYNC: Full sync (sequentially consistent) memory barrier – std::memory_order_seq_cst
  • Caution: Exact behavior is CPU dependent, and compiler dependent before C++11 – if in doubt it's safest to use a Mutex
  • See also EVO_ATOMIC_FENCE()

◆ PtrBaseT [1/2]

typedef PtrBase<T> PtrBaseT

Managed pointer base type.

◆ PtrBaseT [2/2]

typedef PtrBase<T> PtrBaseT

Managed pointer base type.

◆ RunFunc

typedef void*(* RunFunc) (void *)

◆ SleepLock

Sleep-Lock object type (inert) – see SmartLockInert.

◆ This [1/3]

typedef Atomic<T> This

This type.

◆ This [2/3]

typedef AtomicPtr<T> This

This type.

◆ This [3/3]

typedef AtomicPtr<T[]> This

This type.

Function Documentation

◆ Atomic() [1/2]

Atomic ( )
inline

Constructor, initializes with 0.

◆ Atomic() [2/2]

Atomic ( num)
inline

Constructor.

Parameters
numNumber value to initialize with

◆ AtomicFlag()

AtomicFlag ( )
inline

◆ AtomicPtr() [1/12]

AtomicPtr ( )
inline

Default constructor sets as NULL.

◆ AtomicPtr() [2/12]

AtomicPtr ( T *  ptr)
inline

Constructor.

Parameters
ptrPointer to set, NULL for none

◆ AtomicPtr() [3/12]

AtomicPtr ( const T *  ptr)
inline

Constructor.

Parameters
ptrPointer to set, NULL for none

◆ AtomicPtr() [4/12]

AtomicPtr ( const This src)
inline

Copy constructor.

Parameters
srcSource pointer

◆ AtomicPtr() [5/12]

AtomicPtr ( const Base src)
inline

Copy constructor to reference pointer.

Parameters
srcSource pointer

◆ AtomicPtr() [6/12]

AtomicPtr ( const PtrBaseT src)
inline

Copy constructor to reference pointer.

Parameters
srcSource pointer

◆ AtomicPtr() [7/12]

AtomicPtr ( )
inline

Default constructor sets as NULL.

◆ AtomicPtr() [8/12]

AtomicPtr ( T *  ptr)
inline

Constructor.

Parameters
ptrPointer to set, NULL for none

◆ AtomicPtr() [9/12]

AtomicPtr ( const T *  ptr)
inline

Constructor.

Parameters
ptrPointer to set, NULL for none

◆ AtomicPtr() [10/12]

AtomicPtr ( const This src)
inline

Copy constructor.

Parameters
srcSource pointer

◆ AtomicPtr() [11/12]

AtomicPtr ( const Base src)
inline

Copy constructor to reference pointer.

Parameters
srcSource pointer

◆ AtomicPtr() [12/12]

AtomicPtr ( const PtrBaseT src)
inline

Copy constructor to reference pointer.

Parameters
srcSource pointer

◆ SmartLock()

SmartLock ( T &  object,
bool  lock = true 
)
inline

Constructor.

Parameters
objectSynchronization object to use
lockWhether to lock here

◆ SmartLockInert() [1/3]

SmartLockInert ( T &  )
inline

Constructor – arg is ignored.

◆ SmartLockInert() [2/3]

SmartLockInert ( T &  ,
bool   
)
inline

Constructor – args are ignored.

◆ SmartLockInert() [3/3]

SmartLockInert ( T &  ,
ulong   
)
inline

Constructor – args are ignored.

◆ SmartLockRead()

SmartLockRead ( T &  object,
bool  lock = true 
)
inline

Constructor.

Parameters
objectSynchronization object to use
lockWhether to read-lock here

◆ SmartSleepLock()

SmartSleepLock ( T &  object,
ulong  sleep_ms = 1 
)
inline

Constructor.

Parameters
objectSynchronization object to use
sleep_msSleep time in milliseconds while waiting for lock, 0 to leave unlocked

◆ SysMutex()

SysMutex ( )
inline

Constructor.

◆ SysThread()

SysThread ( )
inline

◆ ~SmartLock()

~SmartLock ( )
inline

Destructor, unlocks if locked here.

◆ ~SmartLockRead()

~SmartLockRead ( )
inline

Destructor, unlocks if locked here.

◆ ~SmartSleepLock()

~SmartSleepLock ( )
inline

Destructor, unlocks if locked here.

◆ ~SysMutex()

~SysMutex ( )
inline

Destructor.

  • Must be unlocked, otherwise results are undefined

◆ ~SysThread()

~SysThread ( )
inline

◆ clear() [1/3]

void clear ( MemOrder  mem_order = std::memory_order_seq_cst)

Clear flag (set to false).

◆ clear() [2/3]

This& clear ( )
inline

Clear pointer, setting as null.

Returns
This

◆ clear() [3/3]

This& clear ( )
inline

Clear pointer, setting as null.

Returns
This

◆ compare_set()

bool compare_set ( cmpval,
newval,
MemOrder  mem_order_success = std::memory_order_seq_cst,
MemOrder  mem_order_failure = std::memory_order_acquire 
)
inline

Compare and set, storing new value if comparison matches.

Parameters
cmpvalOld value to compare with
newvalNew value to set if equal to oldval
mem_order_successMemory order constraints to enforce when comparison succeeds
mem_order_failureMemory order constraints to enforce when comparison fails – must not be: EVO_ATOMIC_RELEASE or EVO_ATOMIC_ACQ_REL
  • also must not be stronger ordering than mem_order_success (until C++17)
Returns
Whether successful, false if comparison failed

◆ detach() [1/3]

void detach ( )
inline

◆ detach() [2/3]

T* detach ( )
inline

Detach and return pointer.

  • This returns current pointer and sets to null
Returns
Pointer

◆ detach() [3/3]

T* detach ( )
inline

Detach and return pointer.

  • This returns current pointer and sets to null
Returns
Pointer

◆ exchange()

T exchange ( num,
MemOrder  mem_order = std::memory_order_seq_cst 
)

Exchange current value with new value.

Parameters
numNew value to store
mem_orderMemory order constraints to enforce, except EVO_ATOMIC_CONSUME not supported here
Returns
Replaced value

◆ fetch_add()

T fetch_add ( num,
MemOrder  mem_order = std::memory_order_seq_cst 
)

Add number to value and return the previous value.

Parameters
numNumber to add
mem_orderMemory order constraints to enforce
Returns
Previous value before this

◆ fetch_and()

T fetch_and ( num,
MemOrder  mem_order = std::memory_order_seq_cst 
)

Bitwise AND with value and return the previous value.

Parameters
numNumber to AND with
mem_orderMemory order constraints to enforce
Returns
Previous value before this

◆ fetch_or()

T fetch_or ( num,
MemOrder  mem_order = std::memory_order_seq_cst 
)

Bitwise OR with value and return the previous value.

Parameters
numNumber to OR with
mem_orderMemory order constraints to enforce
Returns
Previous value before this

◆ fetch_sub()

T fetch_sub ( num,
MemOrder  mem_order = std::memory_order_seq_cst 
)

Subtract number to value and return the previous value.

Parameters
numNumber to subtract
mem_orderMemory order constraints to enforce
Returns
Previous value before this

◆ fetch_xor()

T fetch_xor ( num,
MemOrder  mem_order = std::memory_order_seq_cst 
)

Bitwise XOR with value and return the previous value.

Parameters
numNumber toXOR with
mem_orderMemory order constraints to enforce
Returns
Previous value before this

◆ get_tid()

ulong evo::get_tid ( )
inline

Get current thread ID from system.

Returns
Current thread ID

◆ id()

static ulong id ( )
inlinestatic

◆ join()

bool join ( )
inline

◆ load()

T load ( MemOrder  mem_order = std::memory_order_seq_cst) const

Load and return current value.

Parameters
mem_orderMemory order constraints to enforce, must be EVO_ATOMIC_RELAXED, EVO_ATOMIC_CONSUME, EVO_ATOMIC_ACQUIRE, or EVO_ATOMIC_SYNC
Returns
Current value

◆ lock() [1/8]

SmartLockInert& lock ( )
inline

Lock object (no-op).

Returns
This

◆ lock() [2/8]

SmartLock& lock ( )
inline

Lock object, if not already locked by this.

Returns
This

◆ lock() [3/8]

SmartLockInert& lock ( ulong  )
inline

Lock object (no-op).

  • Arg is ignored
    Returns
    This

◆ lock() [4/8]

void lock ( )
inline

Lock object (no-op).

◆ lock() [5/8]

SmartLockRead& lock ( )
inline

Read-Lock object, if not already locked by this.

Returns
This

◆ lock() [6/8]

SmartSleepLock& lock ( ulong  sleep_ms = 1)
inline

Lock object, if not already locked by this.

Parameters
sleep_msSleep time in milliseconds while waiting for lock, 0 to leave unlocked
Returns
This

◆ lock() [7/8]

void lock ( )
inline

Spin-lock flag.

  • This works like a mutex and does a busy wait (using CPU) until flag is clear (false) and atomically sets the flag
  • Call unlock() to unlock (clear flag)
  • Results are undefined (likely deadlock) if unlock() isn't called after each lock() or sleeplock(), or if already locked by the same thread

◆ lock() [8/8]

void lock ( )
inline

Lock mutex.

  • Must call unlock() after each lock(), otherwise results are undefined
  • Results are undefined if already locked by current thread

◆ lock_read()

void lock_read ( )
inline

Read-lock object (no-op).

◆ operator &=()

T operator&= ( num)

Bitwise AND value and return new value.

Returns
Copy of new value after AND

◆ operator T()

operator T ( ) const
inline

Implicit conversion to integer type.

  • Works the same as load()
    Returns
    Current value

◆ operator!()

bool operator! ( ) const
inline

Negation operator checks if NULL/false (0).

Returns
Whether NULL or false (0)

◆ operator!=() [1/5]

bool operator!= ( const This num) const
inline

Compare whether current value is not equal to number.

Parameters
numNumber to compare with
Returns
Whether not equal

◆ operator!=() [2/5]

bool operator!= ( num) const
inline

Compare whether current value is not equal to number.

Parameters
numNumber to compare with
Returns
Whether not equal

◆ operator!=() [3/5]

bool operator!= ( const PtrBaseT ptr) const
inline

Inequality operator.

Parameters
ptrPointer to compare to
Returns
Whether not equal

◆ operator!=() [4/5]

bool operator!= ( const PtrBaseT ptr) const
inline

Inequality operator.

Parameters
ptrPointer to compare to
Returns
Whether not equal

◆ operator!=() [5/5]

bool evo::operator!= ( const PtrBase< T > &  ptr1,
const PtrBase< T, Atomic< T *> > &  ptr2 
)
inline

Inequality operator for managed pointer base and atomic pointer base.

Parameters
ptr1Pointer to compare
ptr2Pointer to compare to
Returns
Whether not equal

◆ operator++() [1/6]

T operator++ ( )

Increment value and return new value.

Returns
Copy of new value after increment

◆ operator++() [2/6]

T operator++ ( int  )

Increment value and return previous value.

Returns
Copy of previous value before increment

◆ operator++() [3/6]

T* operator++ ( )
inline

Prefix increment operator.

Returns
Pointer after increment

◆ operator++() [4/6]

T* operator++ ( int  )
inline

Prefix increment operator.

Returns
Pointer before increment

◆ operator++() [5/6]

T* operator++ ( )
inline

Prefix increment operator.

Returns
Pointer after increment

◆ operator++() [6/6]

T* operator++ ( int  )
inline

Prefix increment operator.

Returns
Pointer before increment

◆ operator+=() [1/3]

T operator+= ( num)

Increment value and return new value.

Returns
Copy of new value after increment

◆ operator+=() [2/3]

This& operator+= ( int  count)
inline

Increment by count operator.

Parameters
countCount to increment
Returns
This

◆ operator+=() [3/3]

This& operator+= ( int  count)
inline

Increment by count operator.

Parameters
countCount to increment
Returns
This

◆ operator--() [1/6]

T operator-- ( )

Decrement value and return new value.

Returns
Copy of new value after decrement

◆ operator--() [2/6]

T operator-- ( int  )

Decrement value and return previous value.

Returns
Copy of previous value before decrement

◆ operator--() [3/6]

T* operator-- ( )
inline

Prefix decrement operator.

Returns
Pointer after decrement

◆ operator--() [4/6]

T* operator-- ( int  )
inline

Postfix decrement operator.

Returns
Pointer before decrement

◆ operator--() [5/6]

T* operator-- ( )
inline

Prefix decrement operator.

Returns
Pointer after decrement

◆ operator--() [6/6]

T* operator-- ( int  )
inline

Postfix decrement operator.

Returns
Pointer before decrement

◆ operator-=() [1/3]

T operator-= ( num)

Decrement value and return new value.

Returns
Copy of new value after decrement

◆ operator-=() [2/3]

This& operator-= ( int  count)
inline

Decrement by count operator.

Parameters
countCount to decrement
Returns
This

◆ operator-=() [3/3]

This& operator-= ( int  count)
inline

Decrement by count operator.

Parameters
countCount to decrement
Returns
This

◆ operator->() [1/2]

const T operator-> ( ) const
inline

Member access operator (const).

  • Only use where T is apointer
  • Results are undefined if pointer is NULL
Returns
Pointer

◆ operator->() [2/2]

T operator-> ( )
inline

Member access operator.

  • Only use where T is apointer
  • Results are undefined if pointer is NULL
Returns
Pointer

◆ operator<() [1/4]

bool operator< ( num) const
inline

Compare whether current value is less than number.

Parameters
numNumber to compare with
Returns
Whether less

◆ operator<() [2/4]

bool operator< ( const PtrBaseT ptr) const
inline

Less-than operator.

Parameters
ptrPointer to compare to
Returns
Whether less than ptr

◆ operator<() [3/4]

bool operator< ( const PtrBaseT ptr) const
inline

Less-than operator.

Parameters
ptrPointer to compare to
Returns
Whether less than ptr

◆ operator<() [4/4]

bool evo::operator< ( const PtrBase< T > &  ptr1,
const PtrBase< T, Atomic< T *> > &  ptr2 
)
inline

Less-than operator for managed pointer base and atomic pointer base.

Parameters
ptr1Pointer to compare
ptr2Pointer to compare to
Returns
Whether less than ptr

◆ operator<=() [1/4]

bool operator<= ( num) const
inline

Compare whether current value is less than or equal to number.

Parameters
numNumber to compare with
Returns
Whether less/equal

◆ operator<=() [2/4]

bool operator<= ( const PtrBaseT ptr) const
inline

Less-than-or-equals operator.

Parameters
ptrPointer to compare to
Returns
Whether less than or equal to ptr

◆ operator<=() [3/4]

bool operator<= ( const PtrBaseT ptr) const
inline

Less-than-or-equals operator.

Parameters
ptrPointer to compare to
Returns
Whether less than or equal to ptr

◆ operator<=() [4/4]

bool evo::operator<= ( const PtrBase< T > &  ptr1,
const PtrBase< T, Atomic< T *> > &  ptr2 
)
inline

Less-than-or-equals operator for managed pointer base and atomic pointer base.

Parameters
ptr1Pointer to compare
ptr2Pointer to compare to
Returns
Whether less than or equal to ptr

◆ operator=() [1/11]

This& operator= ( num)
inline

Store new value.

Parameters
numValue to store
Returns
This

◆ operator=() [2/11]

This& operator= ( const This src)
inline

Copy/Assignment operator.

Parameters
srcSource pointer
Returns
This

◆ operator=() [3/11]

This& operator= ( const Base src)
inline

Assignment operator to reference pointer.

Parameters
srcSource pointer
Returns
This

◆ operator=() [4/11]

This& operator= ( const PtrBaseT src)
inline

Assignment operator to reference pointer.

Parameters
srcSource pointer
Returns
This

◆ operator=() [5/11]

This& operator= ( T *  ptr)
inline

Assignment operator for raw pointer.

Parameters
ptrPointer to set
Returns
This

◆ operator=() [6/11]

This& operator= ( const T *  ptr)
inline

Assignment operator for raw pointer.

Parameters
ptrPointer to set
Returns
This

◆ operator=() [7/11]

This& operator= ( const This src)
inline

Copy/Assignment operator.

Parameters
srcSource pointer
Returns
This

◆ operator=() [8/11]

This& operator= ( const Base src)
inline

Assignment operator to reference pointer.

Parameters
srcSource pointer
Returns
This

◆ operator=() [9/11]

This& operator= ( const PtrBaseT src)
inline

Assignment operator to reference pointer.

Parameters
srcSource pointer
Returns
This

◆ operator=() [10/11]

This& operator= ( T *  ptr)
inline

Assignment operator for raw pointer.

Parameters
ptrPointer to set
Returns
This

◆ operator=() [11/11]

This& operator= ( const T *  ptr)
inline

Assignment operator for raw pointer.

Parameters
ptrPointer to set
Returns
This

◆ operator==() [1/5]

bool operator== ( const This num) const
inline

Compare whether current value is equal to number.

Parameters
numNumber to compare with
Returns
Whether equal

◆ operator==() [2/5]

bool operator== ( num) const
inline

Compare whether current value is equal to number.

Parameters
numNumber to compare with
Returns
Whether equal

◆ operator==() [3/5]

bool operator== ( const PtrBaseT ptr) const
inline

Equality operator.

Parameters
ptrPointer to compare to
Returns
Whether equal

◆ operator==() [4/5]

bool operator== ( const PtrBaseT ptr) const
inline

Equality operator.

Parameters
ptrPointer to compare to
Returns
Whether equal

◆ operator==() [5/5]

bool evo::operator== ( const PtrBase< T > &  ptr1,
const PtrBase< T, Atomic< T *> > &  ptr2 
)
inline

Equality operator for managed pointer base and atomic pointer base.

Parameters
ptr1Pointer to compare
ptr2Pointer to compare to
Returns
Whether equal

◆ operator>() [1/4]

bool operator> ( num) const
inline

Compare whether current value is greater than number.

Parameters
numNumber to compare with
Returns
Whether greater

◆ operator>() [2/4]

bool operator> ( const PtrBaseT ptr) const
inline

Greater-than operator.

Parameters
ptrPointer to compare to
Returns
Whether greater than ptr

◆ operator>() [3/4]

bool operator> ( const PtrBaseT ptr) const
inline

Greater-than operator.

Parameters
ptrPointer to compare to
Returns
Whether greater than ptr

◆ operator>() [4/4]

bool evo::operator> ( const PtrBase< T > &  ptr1,
const PtrBase< T, Atomic< T *> > &  ptr2 
)
inline

Greater-than operator for managed pointer base and atomic pointer base.

Parameters
ptr1Pointer to compare
ptr2Pointer to compare to
Returns
Whether greater than ptr

◆ operator>=() [1/4]

bool operator>= ( num) const
inline

Compare whether current value is greater than or equal to number.

Parameters
numNumber to compare with
Returns
Whether greater/equal

◆ operator>=() [2/4]

bool operator>= ( const PtrBaseT ptr) const
inline

Greater-than-or-equals operator.

Parameters
ptrPointer to compare to
Returns
Whether greater than or equal to ptr

◆ operator>=() [3/4]

bool operator>= ( const PtrBaseT ptr) const
inline

Greater-than-or-equals operator.

Parameters
ptrPointer to compare to
Returns
Whether greater than or equal to ptr

◆ operator>=() [4/4]

bool evo::operator>= ( const PtrBase< T > &  ptr1,
const PtrBase< T, Atomic< T *> > &  ptr2 
)
inline

Greater-than-or-equals operator for managed pointer base and atomic pointer base.

Parameters
ptr1Pointer to compare
ptr2Pointer to compare to
Returns
Whether greater than or equal to ptr

◆ operator^=()

T operator^= ( num)

Bitwise XOR value and return new value.

Returns
Copy of new value after XOR

◆ operator|=()

T operator|= ( num)

Bitwise OR value and return new value.

Returns
Copy of new value after OR

◆ sleeplock() [1/2]

void sleeplock ( ulong  )
inline

Lock object (no-op).

  • Arg is ignored

◆ sleeplock() [2/2]

void sleeplock ( ulong  ms = 1)
inline

Spin-lock flag with a sleep.

  • This works like a mutex and does a busy wait (using CPU) with sleepms() until flag is clear (false) and atomically sets the flag
  • This is generally less wasteful than lock()
  • Call unlock() to unlock (clear flag)
  • Results are undefined (likely deadlock) if unlock() isn't called after each lock() or sleeplock(), or if already locked by the same thread
Parameters
msSleep time in milliseconds while waiting for lock, must be positive

◆ start()

Error start ( RunFunc  run_func,
void *  run_ptr 
)
inline

◆ store()

void store ( num,
MemOrder  mem_order = std::memory_order_seq_cst 
)

Store new value.

Parameters
numValue to store
mem_orderMemory order constraints to enforce, must be EVO_ATOMIC_RELAXED, EVO_ATOMIC_RELEASE, or EVO_ATOMIC_SYNC

◆ test_and_set()

bool test_and_set ( MemOrder  mem_order = std::memory_order_seq_cst)

Atomically set flag (to true) and return the previous value.

Returns
Previous value

◆ trylock() [1/3]

bool trylock ( )
inline

Try to lock (no-op).

Returns
Always succeeds (returns true)

◆ trylock() [2/3]

bool trylock ( )
inline

Try to lock mutex without blocking.

  • This allows polling for a lock without blocking
  • If current thread already has a lock, whether this succeeds is platform dependent – some platforms (Windows) allow nested locks, others don't
  • Caution: Polling with this can starve (never lock) under load (constant locks)
Returns
Whether successful, false if not available

◆ trylock() [3/3]

bool trylock ( ulong  timeout_ms)
inline

Try to lock mutex with a timeout.

  • This allows polling for a lock until timeout
  • If current thread already has a lock, whether this succeeds is platform dependent – some platforms (Windows) allow nested locks, others don't
  • Windows: This does a spin wait (which consumes CPU) since Windows doesn't support timeout on Critical Section lock
    • Caution: This can starve (never lock) in Windows under load (constant locks)
Parameters
timeout_msTimeout in milliseconds
Returns
Whether successful, false on timeout

◆ trylock_read()

bool trylock_read ( )
inline

Try to read-lock (no-op).

Returns
Always succeeds (returns true)

◆ unlock() [1/7]

SmartLockInert& unlock ( )
inline

Unlock object (no-op).

Returns
This

◆ unlock() [2/7]

SmartLock& unlock ( )
inline

Unlock object, if locked by this.

Returns
This

◆ unlock() [3/7]

void unlock ( )
inline

Unlock object (no-op).

◆ unlock() [4/7]

SmartLockRead& unlock ( )
inline

Read-Unlock object, if locked by this.

Returns
This

◆ unlock() [5/7]

SmartSleepLock& unlock ( )
inline

Unlock object, if locked by this.

Returns
This

◆ unlock() [6/7]

void unlock ( )
inline

Spin-unlock flag.

  • Call after lock() to unlock (clear flag)

◆ unlock() [7/7]

void unlock ( )
inline

Unlock mutex.

  • Results are undefined if called while mutex not locked

◆ unlock_read()

void unlock_read ( )
inline

Un-read-lock object (no-op).

◆ yield()

static void yield ( )
inlinestatic

Variable Documentation

◆ attached

bool attached

◆ handle [1/2]

Handle handle

◆ handle [2/2]

Handle handle

Mutex handle – do not modify.

◆ locked_ [1/3]

bool locked_
protected

Whether object is locked by this.

◆ locked_ [2/3]

bool locked_
protected

Whether object is read-locked by this.

◆ locked_ [3/3]

bool locked_
protected

Whether object is read-locked by this.

◆ object_ [1/3]

T& object_

Synchronization object to lock.

◆ object_ [2/3]

T& object_

Synchronization object to read-lock.

◆ object_ [3/3]

T& object_

Synchronization object to read-lock.