Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

atoms::Mutex::Mon Class Reference

#include <mutex.hh>

Inheritance diagram for atoms::Mutex::Mon:

Inheritance graph
[legend]
Collaboration diagram for atoms::Mutex::Mon:

Collaboration graph
[legend]
List of all members.

Detailed Description

Monitor to lock/unlock mutex.

This is the only way to do so for safety.

Definition at line 91 of file mutex.hh.

Public Member Functions

 Mon (Mutex &m, bool l=true)
 Creates the mutex monitor.

 ~Mon ()
 Unlocks the mutex if it is locked.

void lock ()
 Locks the mutex.

bool trylock ()
 Attempts to lock the mutex.

void unlock ()
 Unlocks the mutex.


Static Public Member Functions

void lockboth (Mon &a, Mon &b)
 Locks two mutexes.


Private Attributes

Mutexm
 The mutex to manage.

bool locked
 True iff the mutex is locked through this monitor.


Static Private Attributes

DebugLogger LOGGER

Friends

class Condition
 Conditions directly access the mutex; they pass through the monitor to do so.


Constructor & Destructor Documentation

atoms::Mutex::Mon::Mon Mutex m,
bool  l = true
[inline]
 

Creates the mutex monitor.

The mutex will be locked by default.

Parameters:
m The mutex to manage.
l True iff the mutex should be initially locked.

Definition at line 103 of file mutex.hh.

References lock(), and locked.

Here is the call graph for this function:

atoms::Mutex::Mon::~Mon  )  [inline]
 

Unlocks the mutex if it is locked.

Definition at line 107 of file mutex.hh.

References locked, and unlock().

Here is the call graph for this function:


Member Function Documentation

void atoms::Mutex::Mon::lock  )  [inline]
 

Locks the mutex.

Locking is not interruptible.

Precondition:
This mutex monitor is not locked. The mutex is not locked, except by the current thread with recusion enabled.

Definition at line 155 of file mutex.hh.

References locked, atoms::DebugLogger::logFatal(), LOGGER, m, atoms::Mutex::me, and NULL.

Referenced by lockboth(), and Mon().

Here is the call graph for this function:

void atoms::Mutex::Mon::lockboth Mon a,
Mon b
[static]
 

Locks two mutexes.

This avoids deadlock by always locking the one with the lower memory address first.

Todo:
Maybe this should be extended to support locking N mutexes in deterministic order.

Definition at line 80 of file mutex.cc.

References lock(), and m.

Here is the call graph for this function:

bool atoms::Mutex::Mon::trylock  ) 
 

Attempts to lock the mutex.

Precondition:
This mutex monitor is not locked.
Returns:
True if successfully locked, false if not recursive and locked by any thread, including the current one.

Definition at line 31 of file mutex.cc.

References locked, m, and atoms::Mutex::me.

void atoms::Mutex::Mon::unlock  )  [inline]
 

Unlocks the mutex.

Precondition:
The mutex is locked through this monitor.

Definition at line 175 of file mutex.hh.

References locked, atoms::DebugLogger::logFatal(), LOGGER, m, and atoms::Mutex::me.

Referenced by ~Mon().

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Condition [friend]
 

Conditions directly access the mutex; they pass through the monitor to do so.

Definition at line 94 of file mutex.hh.


Member Data Documentation

bool atoms::Mutex::Mon::locked [private]
 

True iff the mutex is locked through this monitor.

Definition at line 145 of file mutex.hh.

Referenced by lock(), Mon(), trylock(), unlock(), and ~Mon().

DebugLogger atoms::Mutex::Mon::LOGGER [static, private]
 

Reimplemented from atoms::StackOnly.

Referenced by lock(), and unlock().

Mutex& atoms::Mutex::Mon::m [private]
 

The mutex to manage.

Definition at line 142 of file mutex.hh.

Referenced by lock(), lockboth(), trylock(), unlock(), and atoms::Condition::wait().


The documentation for this class was generated from the following files:
Generated on Wed Jun 15 01:20:53 2005 for atoms++ by doxygen 1.3.5