TinyThread++: fast_mutex Class Reference

# fast_mutex Class Reference

Fast mutex class. More...

`#include <fast_mutex.h>`

List of all members.

## 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.

## Detailed Description

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.

Note:
  The "fast" version of this class relies on inline assembler language, which is currently only supported for 32/64-bit Intel x86/AMD64 and PowerPC architectures on a limited number of compilers (GNU g++ and MS Visual C++). For other architectures/compilers, system functions are used instead.

## Member Function Documentation

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.

See also:
  lock_guard

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).

Returns:
  `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.

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

- fast_mutex.h