Kagome
Polkadot Runtime Engine in C++17
|
#include <spin_lock.hpp>
Public Member Functions | |
spin_lock ()=default | |
spin_lock (const spin_lock &)=delete | |
spin_lock (spin_lock &&)=delete | |
spin_lock & | operator= (const spin_lock &)=delete |
spin_lock & | operator= (spin_lock &&)=delete |
void | lock () |
void | unlock () |
Private Attributes | |
std::atomic_flag | flag_ = ATOMIC_FLAG_INIT |
Implements a spin lock synchronization primitive.
Does busy-waiting over an atomic flag, thus the best application would be for the cases when the lock is required for a very short amount of time (to perform very few and finite computational steps under the lock).
An advantage over std::mutex is locking without a call to system's kernel and eliminating expensive context switches.
Can be used with std::lock_guard:
Definition at line 32 of file spin_lock.hpp.
|
default |
|
delete |
|
delete |
void kagome::common::spin_lock::lock | ( | ) |
Acquires the lock.
Blocks thread execution until the other thread releases the lock in a busy-waiting manner.
Definition at line 10 of file spin_lock.cpp.
void kagome::common::spin_lock::unlock | ( | ) |
Releases the lock.
Definition at line 15 of file spin_lock.cpp.
|
private |
Definition at line 54 of file spin_lock.hpp.