Yate
Public Member Functions | List of all members
Lock2 Class Reference

Ephemeral double mutex locking object. More...

#include <yateclass.h>

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
mx1Pointer to the first mutex to lock
mx2Pointer to the second mutex to lock
maxwaitTime in microseconds to wait for each mutex, -1 wait forever

References Lock2::lock().

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

Create the dual lock, try to lock each mutex

Parameters
mx1Reference to the first mutex to lock
mx2Reference to the second mutex to lock
maxwaitTime in microseconds to wait for each mutex, -1 wait forever

References Lock2::lock().

~Lock2 ( )
inline

Destroy the lock, unlock the mutex if it was locked

References Lock2::drop().

Member Function Documentation

void drop ( )

Unlock both mutexes if they were locked and drop the references

Referenced by Lock2::~Lock2().

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

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

Parameters
mx1Pointer to the first mutex to lock
mx2Pointer to the second mutex to lock
maxwaitTime in microseconds to wait for each mutex, -1 wait forever
Returns
True on success - non-NULL mutexes locked

Referenced by Lock2::lock(), and Lock2::Lock2().

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

Lock in a new pair of mutexes

Parameters
mx1Reference to the first mutex to lock
mx2Reference to the second mutex to lock
maxwaitTime in microseconds to wait for each mutex, -1 wait forever
Returns
True on success - both locked

References Lock2::lock().

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: