Yate

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Lock Class Reference

Ephemeral mutex or semaphore locking object. More...

`#include <yateclass.h>`

## Public Member Functions
| Lock (Lockable &lck, long maxwait=-1)
| Lock (Lockable *lck, long maxwait=-1)
| ~Lock ()
Lockable * | locked () const
void | drop ()
bool | acquire (Lockable *lck, long maxwait=-1)
bool | acquire (Lockable &lck, long maxwait=-1)

## Detailed Description

Ephemeral mutex or semaphore locking object.

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

## Constructor & Destructor Documentation

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

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

References Lockable::lock().

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

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

References Lockable::lock().

~Lock | ( |  | ) |
| inline

Destroy the lock, unlock the mutex if it was locked

References Lockable::unlock().

## Member Function Documentation

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

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

References Lock::drop(), and Lockable::lock().

Referenced by Lock::acquire().

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

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

References Lock::acquire().

void drop | ( |  | ) |
| inline

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

References Lockable::unlock().

Referenced by Lock::acquire().

Lockable* locked | ( |  | ) | const
| inline

Return a pointer to the lockable object this lock holds

Returns
  A pointer to a Lockable or NULL if locking failed

The documentation for this class was generated from the following file:

- yateclass.h