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 ( )
boolAmIOwner ( ) const
void *GetHandle ( ) const
boolIsOwned ( ) const
RED_RCReleaseOwnership ( )
RED_RCTakeOwnership ( )
intWaitingCallers ( ) 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:

Functions documentation

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:

true if the caller is the owner of the mutex, false otherwise.
public void * RED::Mutex::GetHandle() const

Returns:

The address of the internal mutex handle.
public bool RED::Mutex::IsOwned() const

Returns:

true if a thread has taken ownership of the mutex, false otherwise.

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_OK when the mutex ownership was correctly released, RED_INIT_FAILED if the mutex did not successfully initialize during its construction time,
RED_FAIL if the thread did not own the mutex.

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_OK when the mutex ownership was correctly acquired,
RED_INIT_FAILED if the mutex did not successfully initialize during its construction time,
RED_FAIL if the thread failed to get ownership.

Returns:

the number of callers waiting for the mutex since the first blocking call.

Variables documentation

protected CRITICAL_SECTION RED::Mutex::_cs

_cs: critical section used internally to protect access to the mutex members.

protected void * RED::Mutex::_handle

_handle: Windows mutex handle.

protected bool RED::Mutex::_owned

_owned: flag indicating if the mutex is currently owned or not.

_waitingCallersCount: number of mutex object requests since the first blocking one.