All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::Mutex Class Reference

Mutual exclusion (or mutex for short) is used to avoid simultaneous use of a shared resource. More...

#include <Radiant/Mutex.hpp>

Inheritance diagram for Radiant::Mutex:
Patterns::NotCopyable

Public Member Functions

void lock ()
 Lock the mutex If another thread has already locked the mutex the calling thread will block until the other thread unlocks the mutex. More...
 
 Mutex (bool recursive=false)
 Construct a mutex. More...
 
bool tryLock ()
 Try to lock the mutex Tries to lock the mutex but does not block if the mutex has already been locked. More...
 
void unlock ()
 Unlock the mutex Must be called from the same thread as the mutex was locked from. More...
 
 ~Mutex ()
 Destructor.
 

Friends

class Condition
 

Detailed Description

Mutual exclusion (or mutex for short) is used to avoid simultaneous use of a shared resource.

A mutex can be recursive. This means the same calling thread can lock the mutex more than once and won't deadlock.

Constructor & Destructor Documentation

Radiant::Mutex::Mutex ( bool  recursive = false)

Construct a mutex.

Parameters
recursiveif true, create a recursive mutex

Member Function Documentation

void Radiant::Mutex::lock ( )

Lock the mutex If another thread has already locked the mutex the calling thread will block until the other thread unlocks the mutex.

bool Radiant::Mutex::tryLock ( )

Try to lock the mutex Tries to lock the mutex but does not block if the mutex has already been locked.

Returns
true if the lock was attained, false otherwise
void Radiant::Mutex::unlock ( )

Unlock the mutex Must be called from the same thread as the mutex was locked from.