|
CppCommon 1.0.5.0
C++ Common Library
|
Spin-lock synchronization primitive. More...
#include <spin_lock.h>
Public Member Functions | |
| SpinLock () noexcept | |
| SpinLock (const SpinLock &)=delete | |
| SpinLock (SpinLock &&)=delete | |
| ~SpinLock ()=default | |
| SpinLock & | operator= (const SpinLock &)=delete |
| SpinLock & | operator= (SpinLock &&)=delete |
| bool | IsLocked () noexcept |
| Is already locked? | |
| bool | TryLock () noexcept |
| Try to acquire spin-lock without block. | |
| bool | TryLockSpin (int64_t spin) noexcept |
| Try to acquire spin-lock for the given spin count. | |
| bool | TryLockFor (const Timespan ×pan) noexcept |
| Try to acquire spin-lock for the given timespan. | |
| bool | TryLockUntil (const UtcTimestamp ×tamp) noexcept |
| Try to acquire spin-lock until the given timestamp. | |
| void | Lock () noexcept |
| Acquire spin-lock with block. | |
| void | Unlock () noexcept |
| Release spin-lock. | |
Spin-lock synchronization primitive.
The purpose of a spin lock is to prevent multiple threads from concurrently accessing a shared data structure. In contrast to a mutex, threads will busy-wait and waste CPU cycles instead of yielding the CPU to another thread. Do not use spinlocks unless you are certain that you understand the consequences!
Thread-safe.
https://en.wikipedia.org/wiki/Spinlock
Definition at line 29 of file spin_lock.h.
|
inlinenoexcept |
Definition at line 32 of file spin_lock.h.
|
delete |
|
delete |
|
default |
|
inlinenoexcept |
Is already locked?
Will not block.
Definition at line 11 of file spin_lock.inl.
|
inlinenoexcept |
Acquire spin-lock with block.
Will block in a spin loop.
Definition at line 50 of file spin_lock.inl.
|
inlinenoexcept |
Try to acquire spin-lock without block.
Will not block.
Definition at line 16 of file spin_lock.inl.
|
inlinenoexcept |
Try to acquire spin-lock for the given timespan.
Will block for the given timespan in the worst case.
| timespan | - Timespan to wait for the spin-lock |
Definition at line 34 of file spin_lock.inl.
|
inlinenoexcept |
Try to acquire spin-lock for the given spin count.
Will block for the given spin count in the worst case.
| spin | - Spin count |
Definition at line 21 of file spin_lock.inl.
|
inlinenoexcept |
Try to acquire spin-lock until the given timestamp.
Will block until the given timestamp in the worst case.
| timestamp | - Timestamp to stop wait for the spin-lock |
Definition at line 80 of file spin_lock.h.
|
inlinenoexcept |