sync.lock.multi ≡
template <auto NumMutexes> class multi_mutex §source
An array of independent mutually exclusive locks, or mutexes. Call
lock to acquire a mutex and unlock to release
it.
Methods
-
void init() §source
-
void lock(index_t<NumMutexes> index) §source
Atomically acquire the lock with the specified index if it is not already acquired otherwise block waiting on the lock to be released.
-
void unlock(index_t<NumMutexes> index) §source
Release the lock with the specified index. You must never unlock a mutex that is not locked, otherwise you will create a deadlock when a thread tries to lock this same mutex.
template <auto MaxThreads, auto NumLocks> class multi_rwlock §source
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 for a single lock. Typically 512 is a sensible value to use here.
-
auto NumLocksThe number of independent rwlocks to create. If we think of this class as implementing a vector of rwlock, then this value represents the vector size.
Methods
-
void init() §source
-
void lock(multi_rwlock::rwlock_index_t index, bool is_reader) §source
Attempt to acquire either a reader or a writer lock for the lock with the specified index.
-
void unlock(multi_rwlock::rwlock_index_t index, bool is_reader) §source
Release a reader or writer lock at the specified index. You must never unlock without having previously acquired the same type of lock, otherwise you will create a deadlock situation.
-
inline void read_lock(multi_rwlock::rwlock_index_t index) §source
Acquire a reader lock on the lock at the specified index.
-
inline void write_lock(multi_rwlock::rwlock_index_t index) §source
Acquire a writer lock on the lock at the specified index.
-
inline void read_unlock(multi_rwlock::rwlock_index_t index) §source
Release a reader lock on the lock at the specified index.
-
inline void write_unlock(multi_rwlock::rwlock_index_t index) §source
Release a writer lock on the lock at the specified index.
template <auto N, auto M, auto I, auto Blocking = true> class multi_semaphore §source
Multiple instance semaphore.
Parameters
-
auto NNumber of semaphore instances.
-
auto MMaximum semaphore value.
-
auto IInitial value for the semaphore count. Must be less than or equal to
M. -
auto Blocking = true
By default, this is true and causes the semaphore to block when wait is called. Setting this to false should only be used when the caller can ensure that the semaphore count is greater than 0 when wait is called. If it is not a diagnostics assert is raised.
Methods
-
inline bool test_and_decrement( multi_semaphore::sem_idx_t which, multi_semaphore::sem_ctr_t val, bool decrement_count ) §source
Check if the current count is greater than or equal to value. If
decrement_countflag is set, and the current count is sufficient, this method will also decrement the count. This function is not inherently threadsafe, and must be called from inside anatomic. -
inline bool wait(multi_semaphore::sem_idx_t which, bool decrement_count) §source
If blocking, wait for the semaphore count to be non-zero and conditionally decrement the count. Otherwise check if the semaphore count is non-zero, conditionally decrement the count, and assert if
decrement_countis true and the count is zero. -
inline bool wait_multiple( multi_semaphore::sem_idx_t which, multi_semaphore::sem_ctr_t val, bool decrement_count ) §source
If blocking, wait for the semaphore count to be greater than or equal to the supplied value and conditionally decrement the count. Otherwise check if the semaphore count is greater than or equal to
val, conditionally decrement the count, and assert ifdecrement_countis true and the count is insufficient. -
inline void post(multi_semaphore::sem_idx_t which) §source
Increment the semaphore count by 1, potentially waking a thread.
-
inline multi_semaphore::sem_ctr_t count(multi_semaphore::sem_idx_t which) §source
Return current value of semaphore. Provided primarily for debug/diagnostic purposes.
-
void post_multiple( multi_semaphore::sem_idx_t which, multi_semaphore::sem_ctr_t amount ) §source
Increment the semaphore count by the specified
amount, potentially waking one or more threads.
Invariants
-
(I <= M)