ion 0.12.0
Atomic concurrency support library
Loading...
Searching...
No Matches
ion::SpinLock Class Reference

Busy spinning lock that satisfies BasicLockable, Lockable and Mutex requirements. More...

#include <ion/spinLock.hpp>

Public Member Functions

 SpinLock (SpinLock const &)=delete
 
void lock () noexcept
 Acquires the lock.
 
ION_FORCE_INLINE bool try_lock () noexcept
 Attempts to acquire the lock.
 
void unlock () noexcept
 Releases held lock.
 

Detailed Description

Busy spinning lock that satisfies BasicLockable, Lockable and Mutex requirements.

Implementation busy-spins without sleeping or yielding, does not detect resource deadlocks and does not throw any exceptions.

Note
This is not suitable for most general programs.

Can be used with e.g. std::lock_guard, std::scoped_lock and std::unique_lock.

Memory Order
See Mutex.
Thread Safety
thread-safe

Member Function Documentation

◆ lock()

void ion::SpinLock::lock ( )
inlinenoexcept

Acquires the lock.

Precondition
lock must not be held.
Postcondition
lock is held.

◆ try_lock()

bool ion::SpinLock::try_lock ( )
inlinenoexcept

Attempts to acquire the lock.

Precondition
lock must not be held.
Returns
true if lock was acquired.
false otherwise.

◆ unlock()

void ion::SpinLock::unlock ( )
inlinenoexcept

Releases held lock.

Precondition
lock must be held.