Yate: Lockable Class Reference

Yate

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | List of all members
Lockable Class Referenceabstract

Abstract interface for lockable objects. More...

`#include <yateclass.h>`

Inheritance diagram for Lockable:

## Public Member Functions
virtual | ~Lockable ()
virtual bool | lock (long maxwait=-1)=0
virtual bool | unlock ()=0
virtual bool | locked () const =0
virtual bool | check (long maxwait=-1)
virtual bool | unlockAll ()

## Static Public Member Functions
static void | wait (unsigned long maxwait)
static unsigned long | wait ()
static void | startUsingNow ()
static void | enableSafety (bool safe=true)
static bool | safety ()

## Detailed Description

Abstract interface for lockable objects.

An abstract base class for implementing lockable objects

## Constructor & Destructor Documentation

virtual ~Lockable | ( |  | ) |
| virtual

Destructor

## Member Function Documentation

virtual bool check | ( | long | maxwait = `-1` | ) |
| virtual

Check if the object is unlocked (try to lock and unlock it)

Parameters

  maxwait | Time in microseconds to wait, -1 to wait forever

Returns
  True if successfully locked and unlocked, false on failure

static void enableSafety | ( | bool | safe = `true` | ) |
| static

Enable some safety and sanity check features. This provides a safer code and easier locking debugging at the price of performance penalty. This method must be called early and not changed after initialization

Parameters

  safe | True to enable locking safety measures, false to disable

virtual bool lock | ( | long | maxwait = `-1` | ) |
| pure virtual

Attempt to lock the object and eventually wait for it

Parameters

  maxwait | Time in microseconds to wait, -1 wait forever

Returns
  True if successfully locked, false on failure

Implemented in Semaphore, and Mutex.

Referenced by Lock::acquire(), and Lock::Lock().

virtual bool locked | ( |  | ) | const
| pure virtual

Check if the object is currently locked - as it's asynchronous it guarantees nothing if other thread changes the status

Returns
  True if the object was locked when the function was called

Implemented in Semaphore, and Mutex.

static bool safety | ( |  | ) |
| static

Retrieve safety and sanity check features flag value

Returns
  Locking safety measures flag value

static void startUsingNow | ( |  | ) |
| static

Start actually using lockables, for platforms where these objects are not usable in global object constructors. This method must be called at least once somewhere from main() but before creating any threads and without holding any object locked.

virtual bool unlock | ( |  | ) |
| pure virtual

Unlock the object, does never wait

Returns
  True if successfully unlocked the object

Implemented in Semaphore, and Mutex.

Referenced by Lock::drop(), and Lock::~Lock().

virtual bool unlockAll | ( |  | ) |
| virtual

Fully unlock the object, even if it was previously multiple locked. There is no guarantee about the object status after the function returns. This function should be used only if you understand it very well

Returns
  True if the object was fully unlocked

static void wait | ( | unsigned long | maxwait | ) |
| static

Set a maximum wait time for debugging purposes

Parameters

  maxwait | Maximum time in microseconds to wait for any lockable object when no time limit was requested, zero to disable limit

static unsigned long wait | ( |  | ) |
| static

Get the maximum wait time used for debugging purposes

Returns
  Maximum time in microseconds, zero if no maximum is set

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

- yateclass.h