# Mutex Class Reference

Mutex support. More...

`#include <yateclass.h>`

Inheritance diagram for Mutex:

List of all members.

## Public Member Functions

| Mutex ()
| Mutex (bool recursive)
| Mutex (const Mutex &original)
| ~Mutex ()
Mutex & | operator= (const Mutex &original)
bool | lock (long maxwait=-1)
void | unlock ()
bool | locked () const
bool | check (long maxwait=-1)
bool | recursive () const

## Static Public Member Functions

static int | count ()
static int | locks ()
static void | wait (unsigned long maxwait)

## Friends

class | MutexPrivate

## Detailed Description

Mutex support.

A simple mutual exclusion for locking access between threads

## Constructor & Destructor Documentation

Mutex | ( |  | ) |

Construct a new unlocked fast mutex

Mutex | ( | bool | recursive | ) |

Construct a new unlocked mutex

Parameters:

  | recursive | True if the mutex has to be recursive (reentrant), false for a normal fast mutex

Mutex | ( | const Mutex & | original | ) |

Copy constructor creates a shared mutex

Parameters:

  | original | Reference of the mutex to share

~Mutex | ( |  | ) |

Destroy the mutex

## Member Function Documentation

Mutex& operator= | ( | const Mutex & | original | ) |

Assignment operator makes the mutex shared with the original

Parameters:

  | original | Reference of the mutex to share

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

Attempt to lock the mutex and eventually wait for it

Parameters:

  | maxwait | Time in microseconds to wait for the mutex, -1 wait forever

Returns:
  True if successfully locked, false on failure

void unlock | ( |  | ) |

Unlock the mutex, does never wait

bool locked | ( |  | ) | const

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

Returns:
  True if the mutex was locked when the function was called

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

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

Parameters:

  | maxwait | Time in microseconds to wait for the mutex, -1 wait forever

Returns:
  True if successfully locked and unlocked, false on failure

bool recursive | ( |  | ) | const

Check if this mutex is recursive or not

Returns:
  True if this is a recursive mutex, false for a fast mutex

static int count | ( |  | ) | `[static]`

Get the number of mutexes counting the shared ones only once

Returns:
  Count of individual mutexes

static int locks | ( |  | ) | `[static]`

Get the number of currently locked mutexes

Returns:
  Count of locked mutexes, should be zero at program exit

static void wait | ( | unsigned long | maxwait | ) | `[static]`

Set a maximum mutex wait time for debugging purposes

Parameters:

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

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

- yateclass.h