A standard mutex, or mutual exclusion lock. More...
#include "pmutex.h"
Public Member Functions | |
Mutex (const char *name) | |
Mutex (const std::string &name) | |
Mutex (const Mutex ©)=delete | |
void | operator= (const Mutex ©)=delete |
![]() | |
void | acquire () const |
Grabs the mutex if it is available. More... | |
void | clear_name () |
The mutex name is only defined when compiling in DEBUG_THREADS mode. More... | |
bool | debug_is_locked () const |
Returns true if the current thread has locked the Mutex, false otherwise. More... | |
std::string | get_name () const |
The mutex name is only defined when compiling in DEBUG_THREADS mode. More... | |
bool | has_name () const |
The mutex name is only defined when compiling in DEBUG_THREADS mode. More... | |
void | lock () |
Alias for acquire() to match C++11 semantics. More... | |
void | output (std::ostream &out) const |
This method is declared virtual in MutexDebug, but non-virtual in MutexDirect. More... | |
void | release () const |
Releases the mutex. More... | |
void | set_name (const std::string &name) |
The mutex name is only defined when compiling in DEBUG_THREADS mode. More... | |
bool | try_acquire () const |
Returns immediately, with a true value indicating the mutex has been acquired, and false indicating it has not. More... | |
bool | try_lock () |
Alias for try_acquire() to match C++11 semantics. More... | |
void | unlock () |
Alias for release() to match C++11 semantics. More... | |
Static Public Attributes | |
static Mutex | _notify_mutex |
A standard mutex, or mutual exclusion lock.
Only one thread can hold ("lock") a mutex at any given time; other threads trying to grab the mutex will block until the holding thread releases it.
The standard mutex is not reentrant: a thread may not attempt to lock it twice. Although this may happen to work on some platforms (e.g. Win32), it will not work on all platforms; on some platforms, a thread can deadlock itself by attempting to lock the same mutex twice. If your code requires a reentrant mutex, use the ReMutex class instead.
This class inherits its implementation either from MutexDebug or MutexDirect, depending on the definition of DEBUG_THREADS.