Mutex

Functions

Mutex

~Mutex

RED_RC

TakeOwnership

RED_RC

ReleaseOwnership

pthread_mutex_t

GetHandle

bool

AmIOwner

bool

IsOwned

int

WaitingCallers

Detailed Description

class Mutex

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:

Public Functions

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.

virtual ~Mutex()

Mutex destruction method.

The object destructor releases the mutex object, even if it was not previously owner.

RED_RC 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_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.

RED_RC 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_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.

inline pthread_mutex_t GetHandle() const
Returns

The address of the internal mutex handle.

inline bool AmIOwner() const
Returns

true if the caller is the owner of the mutex, false otherwise.

inline bool IsOwned() const
Returns

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

inline int WaitingCallers() const
Returns

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