# PWaitAndSignal Class Reference

This class waits for the semaphore on construction and automatically signals the semaphore on destruction. More...

`#include <psync.h>`

List of all members.

## Public Member Functions

| PWaitAndSignal (const PSync &sem, PBoolean wait=true)
| Create the semaphore wait instance.
| ~PWaitAndSignal ()
| Signal the semaphore.

## Protected Attributes

PSync & | sync

## Detailed Description

This class waits for the semaphore on construction and automatically signals the semaphore on destruction.

Any descendent of PSemaphore may be used.

This is very useful for constructs such as:

        void func()
        {
          PWaitAndSignal mutexWait(myMutex);
          if (condition)
            return;
          do_something();
          if (other_condition)
            return;
          do_something_else();
        }

## Constructor & Destructor Documentation

PWaitAndSignal::PWaitAndSignal | ( | const PSync & | sem,
|  | PBoolean | wait = `true` |
| ) |  |  | `[inline]`

Create the semaphore wait instance.

This will wait on the specified semaphore using the Wait() function before returning.

Parameters:

  sem | Semaphore descendent to wait/signal.
  wait | Wait for semaphore before returning.

PWaitAndSignal::~PWaitAndSignal | ( |  | ) | `[inline]`

Signal the semaphore.

This will execute the Signal() function on the semaphore that was used in the construction of this instance.

## Member Data Documentation

PSync& PWaitAndSignal::sync `[protected]`

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

- psync.h