Lock Class Reference

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

#include <lock.h>

Inheritance diagram for Lock:
Inheritance graph
[legend]

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.

Constructor & Destructor Documentation

Lock::Lock (  )  [inline]

References deleted.

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

References deleted.


Member Function Documentation

bool Lock::try_lock ( string  w  ) 

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

References assert(), cmpxchg, deleted, locked, and who.

Referenced by wait_lock().

void Lock::unlock (  ) 

Straightforwardly unlocks the lock.

References assert(), deleted, locked, and who.

Referenced by AutoLock::~AutoLock().

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.

References assert(), deleted, try_lock(), and who.

Referenced by AutoLock::AutoLock().


Member Data Documentation

Referenced by Lock(), try_lock(), unlock(), wait_lock(), and ~Lock().

volatile void* Lock::locked

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

Referenced by try_lock(), and unlock().

string Lock::who

Referenced by try_lock(), unlock(), and wait_lock().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by  doxygen 1.6.2