Overview / System & concurrency

mutex

Recursive mutex with owner tracking and an RAII guard.

Always compiled: part of the core build.Include #include <ethereal/cpp/mutex/mutex_inc.hpp>C layer

mutex_inc.hpp

#include <ethereal/cpp/mutex/mutex_inc.hpp>

mutex.hpp

#include <ethereal/cpp/mutex/mutex.hpp>
class

CMutex

Ethereal::Mutex#

Class that handles a mutex with control of the Lock and Unlock operations. Use it only if you know what you are doing. Otherwise, prefer the scoped version CScopedMutex.

class CMutex final

It must not be inherited directly by any structure, class or object.

constructor

CMutex

#
CMutex() noexcept;

Constructor : initializes the critical section.

function

Lock

#
void Lock( void ) noexcept;

Locks/Activates the Mutex.

function

TryLock

#
bool TryLock( void ) noexcept;

Tries to lock/activate the Mutex.

Result code of the operation: @true: Success, the mutex was locked. @false: Failed to lock the mutex.
function

Unlock

#
void Unlock( void ) noexcept;

Unlocks the Mutex. If the calling thread holds it. Otherwise the call is ignored.

Until 2026-10-11 any thread could unlock it. A thread that did not hold it lowered the lock depth and unlocked a mutex it did not own, which is undefined behavior, and on Linux left the mutex locked for good.

function

SetInternalStatePermit

#
void SetInternalStatePermit( const bool bLockEnabled );

Enables or disables the internal operation of the mutex.

Controls whether the mutex is allowed to perform lock and unlock operations internally. When disabled, synchronization calls are ignored according to the internal policy of the mutex.

This is useful in specific cases such as a controlled shutdown, debugging or single-thread environments.

While disabled, Lock is ignored only for a thread that does not hold the mutex. A thread that already holds it keeps counting its nested locks, and Unlock only releases a lock of the calling thread. So every Unlock pairs with its own Lock, even when the permit changes in between. Until 2026-10-11 the nested Lock did not count, and its Unlock released the outer lock.

bLockEnabled
Tells whether the mutex can lock/unlock.
This function is not thread-safe . The internal state of the mutex must be changed in a controlled context, without concurrent access.
function

IsLockedState

#
bool IsLockedState( void ) const noexcept;

Gets the current lock state of the Mutex: whether some thread holds it.

Safe to call from any thread. From a thread that does not hold the mutex, the answer may already be stale when it returns. Until 2026-10-11 it read the lock depth with no lock, a data race when called from another thread.

class

CScopedMutex

Ethereal::Mutex#
class CScopedMutex final
constructor

CScopedMutex

#
explicit CScopedMutex( CMutex & TargetMutex ) noexcept;

Constructor : locks the critical section of TargetMutex.

TargetMutex
Mutex to lock until the end of the scope. Not owned by the guard.