Lock2 Class Reference

Ephemeral double mutex locking object. More...

#include <yateclass.h>

List of all members.

Public Member Functions

 Lock2 (Mutex *mx1, Mutex *mx2, long maxwait=-1)
 Lock2 (Mutex &mx1, Mutex &mx2, long maxwait=-1)
 ~Lock2 ()
bool locked () const
bool lock (Mutex *mx1, Mutex *mx2, long maxwait=-1)
bool lock (Mutex &mx1, Mutex &mx2, long maxwait=-1)
void drop ()

Detailed Description

Ephemeral double mutex locking object.

A dual lock is a stack allocated (automatic) object that locks a pair of mutexes on creation and unlocks them on destruction. The mutexes are always locked in the same order to prevent trivial deadlocks


Constructor & Destructor Documentation

Lock2 ( Mutex mx1,
Mutex mx2,
long  maxwait = -1 
) [inline]

Create the dual lock, try to lock each mutex

Parameters:
mx1 Pointer to the first mutex to lock
mx2 Pointer to the second mutex to lock
maxwait Time in microseconds to wait for each mutex, -1 wait forever
Lock2 ( Mutex mx1,
Mutex mx2,
long  maxwait = -1 
) [inline]

Create the dual lock, try to lock each mutex

Parameters:
mx1 Reference to the first mutex to lock
mx2 Reference to the second mutex to lock
maxwait Time in microseconds to wait for each mutex, -1 wait forever
~Lock2 (  )  [inline]

Destroy the lock, unlock the mutex if it was locked


Member Function Documentation

void drop (  ) 

Unlock both mutexes if they were locked and drop the references

bool lock ( Mutex mx1,
Mutex mx2,
long  maxwait = -1 
) [inline]

Lock in a new pair of mutexes

Parameters:
mx1 Reference to the first mutex to lock
mx2 Reference to the second mutex to lock
maxwait Time in microseconds to wait for each mutex, -1 wait forever
Returns:
True on success - both locked

References Lock2::lock().

Referenced by Lock2::lock().

bool lock ( Mutex mx1,
Mutex mx2,
long  maxwait = -1 
)

Lock in a new pair of mutexes. Any existing locks are dropped

Parameters:
mx1 Pointer to the first mutex to lock
mx2 Pointer to the second mutex to lock
maxwait Time in microseconds to wait for each mutex, -1 wait forever
Returns:
True on success - non-NULL mutexes locked
bool locked (  )  const [inline]

Check if the locking succeeded

Returns:
True if all mutexes were locked

The documentation for this class was generated from the following file:
Generated on Thu Apr 8 18:19:41 2010 for Yate by  doxygen 1.6.3