ezEngine  Release 25.03
ezMutex Class Reference

Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared resource simultaneously. More...

#include <Mutex.h>

Inheritance diagram for ezMutex:

Public Member Functions

void Lock ()
 Acquires an exclusive lock for this mutex object.
 
ezResult TryLock ()
 Attempts to acquire an exclusive lock for this mutex object. Returns true on success. More...
 
void Unlock ()
 Releases a lock that has been previously acquired.
 
EZ_ALWAYS_INLINE bool IsLocked () const
 Returns true, if the mutex is currently acquired. Can be used to assert that a lock was entered. More...
 
ezMutexHandle & GetMutexHandle ()
 

Detailed Description

Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared resource simultaneously.

This can be used to protect code that is not thread-safe against race conditions. To ensure that mutexes are always properly released, use the ezLock class or EZ_LOCK macro.

See also
ezSemaphore, ezConditionVariable

Member Function Documentation

◆ IsLocked()

EZ_ALWAYS_INLINE bool ezMutex::IsLocked ( ) const
inline

Returns true, if the mutex is currently acquired. Can be used to assert that a lock was entered.

Obviously, this check is not thread-safe and should not be used to check whether a mutex could be locked without blocking. Use TryLock for that instead.

◆ TryLock()

ezResult ezMutex::TryLock ( )
inline

Attempts to acquire an exclusive lock for this mutex object. Returns true on success.

If the mutex is already acquired by another thread, the function returns immediately and returns false.


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