Om  1.0.0
A universal framework for multimedia simulation
Public Member Functions | List of all members
om::threads::Mutex Class Reference

A class whose job is to provide a means of thread synchronization by exclusion. More...

#include <omMutex.h>

Public Member Functions

 Mutex ()
 Create a new mutex in the default state of not locked. More...
 
 Mutex (const Mutex &other)
 Create a copy of a Mutex object. More...
 
 ~Mutex ()
 Destroy a Mutex object, releasing all internal state. More...
 
Mutexoperator= (const Mutex &other)
 Assign one Mutex to another. More...
 
Bool tryLock ()
 Try to lock a mutex, but return immediately if it is already locked. More...
 
Bool lock ()
 Wait until the Mutex is available for the current thread of execution. More...
 
Bool unlock ()
 Release the mutex so that another thread can acquire it. More...
 
Bool isLocked () const
 Get whether or not the mutex is available. More...
 

Detailed Description

A class whose job is to provide a means of thread synchronization by exclusion.

The class is essentially a wrapper around the host platform's mutex facilities. It allows threads to be synchronized so that access to data or other sensitive items can be restricted to one thread at a time.

In order to use the class properly, call the lock() method to lock the mutex and call the unlock() method to unlock it. The lock() method blocks execution of the calling thread until the mutex has been released by another thread. One can also query the state of the mutex (locked or unlocked) using the method isUnlocked().

Constructor & Destructor Documentation

om::threads::Mutex::Mutex ( )

Create a new mutex in the default state of not locked.

om::threads::Mutex::Mutex ( const Mutex other)

Create a copy of a Mutex object.

The new mutex is created in the unlocked state and is independent of the other mutex. The effect is the same as the default constructor.

om::threads::Mutex::~Mutex ( )

Destroy a Mutex object, releasing all internal state.

Member Function Documentation

Mutex& om::threads::Mutex::operator= ( const Mutex other)

Assign one Mutex to another.

This operator releases any previous lock on this mutex and effectively results in a new mutex in the unlocked state. The new mutex is independent of the other mutex.

Bool om::threads::Mutex::tryLock ( )

Try to lock a mutex, but return immediately if it is already locked.

The mutex is only locked if it is available.

The method returns whether or not the mutex was locked.

Bool om::threads::Mutex::lock ( )

Wait until the Mutex is available for the current thread of execution.

This method blocks the current thread until the signal is recieved that the Mutex has been released, at which time the Mutex is acquired by the current thread and the method returns. If the Mutex is available, the method returns immediately and the Mutex is acquired.

The method returns whether or not the operation was successful.

Bool om::threads::Mutex::unlock ( )

Release the mutex so that another thread can acquire it.

If the mutex is not already acquired, this method has no effect.

The method returns whether or not the operation was successful.

Bool om::threads::Mutex::isLocked ( ) const

Get whether or not the mutex is available.

If the mutex is free for acquisition, TRUE is returned. Otherwise FALSE is returned.

Returns
whether or not the mutex is available for acquisition.

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