Spinmutex class. More...
Public Member Functions
|Default Constructor. |
|Lock the mutex. More...|
|Tries to acquire a lock. More...|
|Unlocks the mutex. |
The most lightweight synchronisation object is the SpinMutex. It is usually implemented with a status variable that can be set to locked and unlocked and atomic operations to change and inspect the status. When lock() is called, the status is changed to Locked. Subsequent calls of lock() from other threads will block until the first thread has called unlock() and the state of the Spinlock has changed to Unlocked. Note that SpinMutexes are not recursive. When a lock() blocks a busy-wait happens, therefore a SpinMutex is only usable in cases where resources need to be locked for a very short time, but in these cases a higher performance can be achieved.
Locks the Spinlock. If the Spinlock is currently locked by another thread, the calling thread suspends until no other thread holds a lock on it. This happens performing a busy-wait. Spinlocks are not recursive locking it multiple times before unlocking it is undefined.
Immediately returns true if successful, or false if one or more other threads currently hold locks.