Plasma Engine  2.0
Loading...
Searching...
No Matches
plMutex 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 plMutex:

Public Member Functions

void Lock ()
 Acquires an exclusive lock for this mutex object.
 
plResult TryLock ()
 Attempts to acquire an exclusive lock for this mutex object. Returns true on success.
 
void Unlock ()
 Releases a lock that has been previously acquired.
 
PL_ALWAYS_INLINE bool IsLocked () const
 Returns true, if the mutex is currently acquired. Can be used to assert that a lock was entered.
 
plMutexHandle & 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 plLock class or PL_LOCK macro.

See also
plSemaphore, plConditionVariable

Member Function Documentation

◆ IsLocked()

PL_ALWAYS_INLINE bool plMutex::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()

plResult plMutex::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: