SpinMutex Class Reference
Spinmutex class.
More...
#include <cxxtools/mutex.h>
List of all members.
|
Public Member Functions |
|
| SpinMutex () |
| | Default Constructor.
|
|
| ~SpinMutex () |
| | Destructor.
|
| void | lock () |
| | Lock.
|
|
bool | tryLock () |
|
void | unlock () |
| | Unlocks the Spinlock.
|
|
bool | testIsLocked () const |
Detailed Description
The most lightweight synchronisation object is the Spinlock. 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 Spinlock::lock is called, the status is changed to Locked. Subsequent calls of Spinlock::lock from other threads will block until the first thread has called Spinlock::unlock and the state of the Spinlock has changed to Unlocked. Note that Spinlocks are not recursive. When a Spinlock::lock blocks a busy-wait happens, therefore a Spinlock 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.
Member Function Documentation
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.