Yate
Lock Class Reference

Ephemeral mutex, semaphore or rw-lock locking object. More...

#include <yateclass.h>

Public Member Functions

 Lock (Lockable &lck, long maxwait=-1, bool readLock=false)
 
 Lock (Lockable *lck, long maxwait=-1, bool readLock=false)
 
 ~Lock ()
 
Lockablelocked () const
 
void drop ()
 
bool acquire (Lockable *lck, long maxwait=-1, bool readLock=false)
 
bool acquire (Lockable &lck, long maxwait=-1, bool readLock=false)
 

Detailed Description

Ephemeral mutex, semaphore or rw-lock 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() [1/2]

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

Create the lock, try to lock the object

Parameters
lckReference to the object to lock
maxwaitTime in microseconds to wait, -1 wait forever
readLockRead lock a RWLock

◆ Lock() [2/2]

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

Create the lock, try to lock the object

Parameters
lckPointer to the object to lock
maxwaitTime in microseconds to wait, -1 wait forever
readLockRead lock a RWLock

◆ ~Lock()

~Lock ( )
inline

Destroy the lock, unlock the mutex if it was locked

Member Function Documentation

◆ acquire() [1/2]

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

Attempt to acquire a new lock on another object

Parameters
lckReference to the object to lock
maxwaitTime in microseconds to wait, -1 wait forever
readLockRead lock a RWLock
Returns
True if locking succeeded or same object was locked

◆ acquire() [2/2]

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

Attempt to acquire a new lock on another object

Parameters
lckPointer to the object to lock
maxwaitTime in microseconds to wait, -1 wait forever
readLockRead lock a RWLock
Returns
True if locking succeeded or same object was locked

References Lockable::lock(), Lockable::lockableRWLock(), and RWLock::readLock().

◆ drop()

void drop ( )
inline

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

◆ locked()

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: