# MutexDirect¶

class MutexDirect

This class implements a standard mutex by making direct calls to the underlying implementation layer. It doesn’t perform any debugging operations.

Inheritance diagram

void acquire(void) const

Grabs the mutex if it is available. If it is not available, blocks until it becomes available, then grabs it. In either case, the function does not return until the mutex is held; you should then call unlock().

This method is considered const so that you can lock and unlock const mutexes, mainly to allow thread-safe access to otherwise const data.

Also see MutexHolder.

void clear_name(void)

The mutex name is only defined when compiling in DEBUG_THREADS mode.

bool debug_is_locked(void) const

Returns true if the current thread has locked the Mutex, false otherwise. This method is only intended for use in debugging, hence the method name; in the MutexDirect case, it always returns true, since there’s not a reliable way to determine this otherwise.

std::string get_name(void) const

The mutex name is only defined when compiling in DEBUG_THREADS mode.

bool has_name(void) const

The mutex name is only defined when compiling in DEBUG_THREADS mode.

void output(std::ostream &out) const

This method is declared virtual in MutexDebug, but non-virtual in MutexDirect.

void release(void) const

Releases the mutex. It is an error to call this if the mutex was not already locked.

This method is considered const so that you can lock and unlock const mutexes, mainly to allow thread-safe access to otherwise const data.

void set_name(std::string const &name)

The mutex name is only defined when compiling in DEBUG_THREADS mode.

bool try_acquire(void) const

Returns immediately, with a true value indicating the mutex has been acquired, and false indicating it has not.