# class Lock2 | Ephemeral double mutex locking object. More...
Full name | `TelEngine::Lock2`
Definition | `#include <yateclass.h>`
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

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

## Detailed Description

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

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

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

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

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

inline ~Lock2 () | ### ~Lock2

Destroy the lock, unlock the mutex if it was locked

inline bool locked () | ### locked

[const]

Check if the locking succeeded

Returns: True if all mutexes were locked

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

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

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

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

void drop () | ### drop

Unlock both mutexes if they were locked and drop the references

Generated by: paulc on bussard on Mon Feb 10 13:15:47 2014, using kdoc 2.0a54.