qb
2.0.0.0
C++17 Actor Framework
|
A spinlock implementation for lightweight thread synchronization. More...
#include <spinlock.h>
Public Member Functions | |
SpinLock () noexcept | |
Default constructor that initializes the lock to unlocked state. | |
SpinLock (const SpinLock &)=delete | |
Copy constructor is deleted to prevent copying of locks. | |
SpinLock (SpinLock &&)=delete | |
Move constructor is deleted to prevent moving of locks. | |
~SpinLock ()=default | |
Default destructor. | |
SpinLock & | operator= (const SpinLock &)=delete |
Copy assignment operator is deleted to prevent copying of locks. | |
SpinLock & | operator= (SpinLock &&)=delete |
Move assignment operator is deleted to prevent moving of locks. | |
bool | locked () noexcept |
Check if the spinlock is currently locked. | |
bool | trylock () noexcept |
Try to acquire the lock without spinning. | |
bool | trylock (int64_t spin) noexcept |
Try to acquire the lock with a maximum number of spin attempts. | |
bool | trylock_for (const Timespan ×pan) noexcept |
Try to acquire the lock for a specified time duration. | |
bool | trylock_until (const UtcTimestamp ×tamp) noexcept |
Try to acquire the lock until a specified point in time. | |
void | lock () noexcept |
Acquire the lock, waiting indefinitely if necessary. | |
void | unlock () noexcept |
Release the lock. |
A spinlock implementation for lightweight thread synchronization.
A spinlock is a lock that causes a thread trying to acquire it to wait in a loop ("spin") while repeatedly checking if the lock is available. This implementation provides methods to acquire the lock with various strategies such as trying for a specific duration or spin count.
|
inlinenoexcept |
Check if the spinlock is currently locked.
|
inlinenoexcept |
Try to acquire the lock without spinning.
This method attempts to acquire the lock once and returns immediately regardless of success.
|
inlinenoexcept |
Try to acquire the lock with a maximum number of spin attempts.
This method attempts to acquire the lock, spinning for up to 'spin' iterations if necessary.
spin | Maximum number of spin iterations |
|
inlinenoexcept |
Try to acquire the lock for a specified time duration.
This method attempts to acquire the lock, spinning until either the lock is acquired or the specified duration has elapsed.
timespan | Maximum duration to try acquiring the lock |
|
inlinenoexcept |
Try to acquire the lock until a specified point in time.
This method attempts to acquire the lock, spinning until either the lock is acquired or the specified timestamp is reached.
timestamp | Point in time until which to try acquiring the lock |
|
inlinenoexcept |
Acquire the lock, waiting indefinitely if necessary.
This method spins until the lock is acquired, with no timeout. It should be used with caution as it can potentially cause deadlocks or waste CPU resources if the lock is held for a long time.
|
inlinenoexcept |
Release the lock.
This method releases the lock, allowing other threads to acquire it.