Lock Class Reference

Atomic non-recursive waiting or non-waiting lock. More...

#include <lock.h>

Inherited by ActiveObject< message >, ActiveObject< ActiveAoTracker_msg_ * >, ActiveObject< ActiveDemoReceiver_msg_ * >, and ActiveObject< ActiveDemoSender_msg_ * >.

List of all members.

Public Member Functions

 Lock ()
bool try_lock (string w)
void wait_lock (string w)
void unlock ()
virtual ~Lock ()

Public Attributes

volatile void * locked
string who
bool deleted


Detailed Description

Atomic non-recursive waiting or non-waiting lock.

The lock class implements an atomic lock through a cmpxchg. It does not provide a counting lock. The main reason for this is that it forces the programmer to think about his locking system. If he needs to avoid locking the same object multiple times then the performance of the program in general improves. The lock will remember who currently obtained the lock through a string that must be passed when locking

See also:
AutoLock for a handy one-liner.

Definition at line 46 of file lock.h.


Constructor & Destructor Documentation

Lock::Lock (  )  [inline]

Definition at line 55 of file lock.h.

virtual Lock::~Lock (  )  [inline, virtual]

Definition at line 78 of file lock.h.


Member Function Documentation

bool Lock::try_lock ( string  w  ) 

Will try to lock the object. Returns true under success, false otherwise.

Definition at line 34 of file lock.cpp.

Here is the caller graph for this function:

void Lock::unlock (  ) 

Straightforwardly unlocks the lock.

Definition at line 70 of file lock.cpp.

Here is the caller graph for this function:

void Lock::wait_lock ( string  w  ) 

Will lock the object, with a complete disregard who asks the lock. If the lock is asked by the same thread that has the lock then it will still be a deadlock. I believe this annoyance forces the programmer to think and improve his program. If wait is true then the call will try for 60s to acquire the lock. If that fails, it will assert itself. if wait is false, the lock return true or false depending on a successful acquisition.

Definition at line 55 of file lock.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 54 of file lock.h.

volatile void* Lock::locked

can be used as a boolean. NULL is unlocked, another value otherwise.

Definition at line 52 of file lock.h.

string Lock::who

Definition at line 53 of file lock.h.


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

Generated on Sun Apr 4 23:26:09 2010 for Active Objects by  doxygen 1.5.9