cxxtools::SpinMutex Class Reference

Spinmutex class. More...

#include <cxxtools/mutex.h>

Inheritance diagram for cxxtools::SpinMutex:
cxxtools::NonCopyable

Public Member Functions

 SpinMutex ()
 Default Constructor.
 ~SpinMutex ()
 Destructor.
void lock ()
 Lock.
bool tryLock ()
void unlock ()
 Unlocks the Spinlock.
bool testIsLocked () const

Additional Inherited Members

- Private Member Functions inherited from cxxtools::NonCopyable
 NonCopyable ()

Detailed Description

Spinmutex class.

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.

Constructor & Destructor Documentation

cxxtools::SpinMutex::SpinMutex ( )
inline

Default Constructor.

cxxtools::SpinMutex::~SpinMutex ( )
inline

Destructor.

Member Function Documentation

void cxxtools::SpinMutex::lock ( )
inline

Lock.

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.

bool cxxtools::SpinMutex::testIsLocked ( ) const
inline
bool cxxtools::SpinMutex::tryLock ( )
inline
void cxxtools::SpinMutex::unlock ( )
inline

Unlocks the Spinlock.


The documentation for this class was generated from the following file: