PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PWaitAndSignal Class Reference

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

#include <psync.h>

Collaboration diagram for PWaitAndSignal:

Public Member Functions

__inline PWaitAndSignal (const PSync &sem)
 Create the semaphore wait instance. More...
 
__inline PWaitAndSignal (const PSync &sem, bool wait)
 
__inline ~PWaitAndSignal ()
 Signal the semaphore. More...
 

Protected Attributes

PSyncsync
 

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

__inline PWaitAndSignal::PWaitAndSignal ( const PSync sem)
inlineexplicit

Create the semaphore wait instance.

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

Parameters
semSemaphore descendent to wait/signal.

References sync, and PSync::Wait().

__inline PWaitAndSignal::PWaitAndSignal ( const PSync sem,
bool  wait 
)
inline
Parameters
semSemaphore descendent to wait/signal.
waitWait for semaphore before returning.

References sync, and PSync::Wait().

__inline PWaitAndSignal::~PWaitAndSignal ( )
inline

Signal the semaphore.

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

References PSync::Signal(), and sync.

Member Data Documentation

PSync& PWaitAndSignal::sync
protected

Referenced by PWaitAndSignal(), and ~PWaitAndSignal().


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