#include <bsls_spinlock.h>
A statically-initializable synchronization primitive that "spins" (i.e., executes user instructions in a tight loop) rather than blocking waiting threads using system calls. The following idiom is used to initialize SpinLock variables:
#define BSLS_SPINLOCK_UNLOCKED
Definition bsls_spinlock.h:326
Definition bsls_spinlock.h:383
void lock()
Definition bsls_spinlock.h:600
A class member d_lock of type SpinLock may be initialized using the following idiom:
static const SpinLock s_unlocked
Definition bsls_spinlock.h:462
See bsls_spinlock
|
| AtomicOperations::AtomicTypes::Int | d_state |
| |
◆ lock()
| void bsls::SpinLock::lock |
( |
| ) |
|
|
inline |
Spin (repeat a loop continuously without using the system to pause or reschedule the thread) until this object is unlocked, then atomically acquire the lock.
◆ lockWithBackoff()
| void bsls::SpinLock::lockWithBackoff |
( |
| ) |
|
|
inline |
Repeat a loop continuously, potentially using the system to pause or reschedule the thread, until this object is unlocked, then atomically acquire the lock. The spinning has backoff logic.
- Note
- Note that this method is recommended when system calls are permissible, significant contention is expected, and no better mutual exclusion primitive is available.
◆ lockWithoutBackoff()
| void bsls::SpinLock::lockWithoutBackoff |
( |
| ) |
|
|
inline |
Spin (repeat a loop continuously without using the system to pause or reschedule the thread) until this object is unlocked, then atomically acquire the lock. The spinning does not perform a backoff.
◆ tryLock()
| int bsls::SpinLock::tryLock |
( |
int |
numRetries = 0 | ) |
|
|
inline |
Attempt to acquire the lock; optionally specify the numRetries times to attempt again if this object is already locked. Return 0 on success, and a non-zero value if the lock was not successfully acquired.
- Precondition
- The behavior is undefined unless
0 <= numRetries.
◆ unlock()
| void bsls::SpinLock::unlock |
( |
| ) |
|
|
inline |
Release the lock.
- Precondition
- The behavior is undefined unless the current thread holds the lock.
◆ d_state
| AtomicOperations::AtomicTypes::Int bsls::SpinLock::d_state |
0 when unlocked. 'd_state is public to allow aggregate initialization where constexpr constructors are not available. It is semantically private, and should not be used directly.
◆ s_unlocked
| const SpinLock bsls::SpinLock::s_unlocked |
|
static |
The documentation for this struct was generated from the following file: