# class Lock

Ephemeral mutex or semaphore locking object. More...

Full name | `TelEngine::Lock`
Definition | `#include <yateclass.h>`
List of all Methods

Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- inline Lock (Lockable& lck, long maxwait = -1)
- inline Lock (Lockable* lck, long maxwait = -1)
- inline ~Lock ()
- inline Lockable* locked () const
- inline void drop ()
- inline bool acquire (Lockable* lck, long maxwait = -1)
- inline bool acquire (Lockable& lck, long maxwait = -1)

## Detailed Description

A lock is a stack allocated (automatic) object that locks a lockable object on creation and unlocks it on destruction - typically when exiting a block

inline Lock (Lockable& lck, long maxwait = -1)

### Lock

Create the lock, try to lock the object

Parameters:

lck | Reference to the object to lock
maxwait | Time in microseconds to wait, -1 wait forever

inline Lock (Lockable* lck, long maxwait = -1)

### Lock

Create the lock, try to lock the object

Parameters:

lck | Pointer to the object to lock
maxwait | Time in microseconds to wait, -1 wait forever

inline ~Lock ()

### ~Lock

Destroy the lock, unlock the mutex if it was locked

inline Lockable* locked ()

### locked

[const]

Return a pointer to the lockable object this lock holds

Returns: A pointer to a Lockable or NULL if locking failed

inline void drop ()

### drop

Unlock the object if it was locked and drop the reference to it

inline bool acquire (Lockable* lck, long maxwait = -1)

### acquire

Attempt to acquire a new lock on another object

Parameters:

lck | Pointer to the object to lock
maxwait | Time in microseconds to wait, -1 wait forever

Returns: True if locking succeeded or same object was locked

inline bool acquire (Lockable& lck, long maxwait = -1)

### acquire

Attempt to acquire a new lock on another object

Parameters:

lck | Reference to the object to lock
maxwait | Time in microseconds to wait, -1 wait forever

Returns: True if locking succeeded or same object was locked

Generated by: paulc on bussard on Fri Dec 21 16:28:34 2012, using kdoc 2.0a54.