Fast mutex class. More...
#include <fast_mutex.h>
Public Member Functions | |
fast_mutex () | |
Constructor. | |
~fast_mutex () | |
Destructor. | |
void | lock () |
Lock the mutex. | |
bool | try_lock () |
Try to lock the mutex. | |
void | unlock () |
Unlock the mutex. |
Fast mutex class.
This is a mutual exclusion object for synchronizing access to shared memory areas for several threads. It is similar to the tthread::mutex class, but instead of using system level functions, it is implemented as an atomic spin lock with very low CPU overhead.
The fast_mutex
class is NOT compatible with the condition_variable
class (however, it IS compatible with the lock_guard
class). It should also be noted that the fast_mutex
class typically does not provide as accurate thread scheduling as a the standard mutex
class does.
Because of the limitations of the class, it should only be used in situations where the mutex needs to be locked/unlocked very frequently.
void lock | ( | ) | [inline] |
Lock the mutex.
The method will block the calling thread until a lock on the mutex can be obtained. The mutex remains locked until unlock()
is called.
bool try_lock | ( | ) | [inline] |
Try to lock the mutex.
The method will try to lock the mutex. If it fails, the function will return immediately (non-blocking).
true
if the lock was acquired, or false
if the lock could not be acquired. void unlock | ( | ) | [inline] |
Unlock the mutex.
If any threads are waiting for the lock on this mutex, one of them will be unblocked.