sync.lock ≡
class mutex §
Mutex: mutually exclusive lock. Call lock to acquire the
mutex and unlock to release it. You would typically use
this class in instances where you have code that implements a
read-modify-write pattern on some variable(s) which takes multiple
cycles to complete. In cases where this operation could be completed
within a single clock cycle, you may consider instead putting the code
in a function which internally uses the atomic keyword to
encapsulate the read-modify-write.
template <auto MaxThreads> class rwlock §
Reader-Writer lock is a synchronization primitive that allows multiple “threads” to acquire a read-lock, but only one thread may have (any) lock if that thread has the write lock.
Parameters
-
auto MaxThreadsThe maximum number of threads that might be manipulating the lock. This determines the maximum number of read-locks that can be outstanding. Typically 512 is a reasonable value to use here.
template <auto M, auto I, auto Blocking = true> class semaphore §
Parameters
-
auto MMaximum semaphore value.
-
auto IInitial value for the semaphore count. Must be less than or equal to
M. -
auto Blocking = true
When true, this parameter causes the semaphore to block when wait is called. Setting to false should only be used when the caller can ensure that the semaphore count is greater than 0 when wait is called otherwise a
assertis raised.
Methods
-
inline bool test_and_decrement(semaphore::sem_ctr_t val) §
Decrement the counter if the current count is greater or equal than
val. This function is not inherently threadsafe and must be called from inside anatomic. -
void wait() §
Decrement the semaphore count by 1 if it is nonzero otherwise block.
-
void wait_multiple(semaphore::sem_ctr_t val) §
Decrement the semaphore count by
valif it is nonzero otherwise block. -
inline void post() §
Increment the semaphore count by 1, potentially waking a thread.
-
inline semaphore::sem_ctr_t count() §
Return current value of semaphore. Provided primarily for debug/diagnostic purposes.
-
void post_multiple(semaphore::sem_ctr_t amount) §
Increment the semaphore count by the specified
amount, potentially waking one or more threads.
Invariants
-
(I <= M)