class RED::Mutex
Mutex class: Have a thread waiting to get the right to continue it's execution. More...
#include <REDMutex.h>
Public functions:
Mutex ( ) | |
virtual | ~Mutex ( ) |
bool | AmIOwner ( ) const |
void * | GetHandle ( ) const |
bool | IsOwned ( ) const |
RED_RC | ReleaseOwnership ( ) |
RED_RC | TakeOwnership ( ) |
int | WaitingCallers ( ) const |
Protected variables:
CRITICAL_SECTION | _cs |
void * | _handle |
bool | _owned |
int | _waitingCallersCount |
Detailed description:
Mutex class: Have a thread waiting to get the right to continue it's execution.
This class encapsulates the mutex class for all REDsdk supported operating systems. This class aims at being very simple, and does not expose advanced mutes features:
- Instantiate a mutex,
- Call RED::Mutex::TakeOwnership to request the mutex handle.
- Call RED::Mutex::ReleaseOwnership to release the mutex handle.
Functions documentation
public RED::Mutex::Mutex | ( | ) |
Mutex construction method without any external identifier.
The created mutex is not owned by anyone. This mutex is not linked to any other mutex. This mutex object instance should be used by all threads that want to share this locking mutex.
public virtual RED::Mutex::~Mutex | ( | ) |
Mutex destruction method.
The object destructor releases the mutex object, even if it was not previously owner.
public bool RED::Mutex::AmIOwner | ( | ) const |
Returns:
public void * RED::Mutex::GetHandle | ( | ) const |
Returns:
public bool RED::Mutex::IsOwned | ( | ) const |
Returns:
public RED_RC RED::Mutex::ReleaseOwnership | ( | ) |
Release the ownership of a mutex that was acquired.
The calling thread decides to release the ownership of the mutex it has. Note that the routine fails if a release call is made for a thread that does not own the mutex. This call is non blocking.
Returns:
RED_FAIL if the thread did not own the mutex.
public RED_RC RED::Mutex::TakeOwnership | ( | ) |
Blocking call that request the mutex ownership.
Calling this method may stall the thread performing the call if another thread owns the mutex. The caller will remain blocked until the mutex has been released by its previous owner, and is available to the calling thread.
Returns:
RED_INIT_FAILED if the mutex did not successfully initialize during its construction time,
RED_FAIL if the thread failed to get ownership.
public int RED::Mutex::WaitingCallers | ( | ) const |
Returns:
Variables documentation
_cs: critical section used internally to protect access to the mutex members.
_handle: Windows mutex handle.
_owned: flag indicating if the mutex is currently owned or not.
_waitingCallersCount: number of mutex object requests since the first blocking one.