psync.h
Go to the documentation of this file.
/*
* psync.h
*
* Abstract synchronisation semaphore class.
*
* Portable Tools Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
* Copyright (c) 2005 Post Increment
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 27923 $
* $Author: rjongbloed $
* $Date: 2012-06-27 22:28:36 -0500 (Wed, 27 Jun 2012) $
*/
#ifndef PTLIB_SYNC_H
#define PTLIB_SYNC_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptlib/contain.h>
#include <ptlib/object.h>
class PSync : public PObject
{
public:
virtual void Wait() = 0;
virtual void Signal() = 0;
};
class PSyncNULL : public PSync
{
public:
virtual void Wait() { }
virtual void Signal() { }
};
class PWaitAndSignal {
public:
inline PWaitAndSignal(
const PSync & sem,
PBoolean wait = true
) : sync((PSync &)sem)
{ if (wait) sync.Wait(); }
~PWaitAndSignal()
{ sync.Signal(); }
protected:
PSync & sync;
};
#endif // PTLIB_SYNC_H
// End Of File ///////////////////////////////////////////////////////////////
PWaitAndSignal
This class waits for the semaphore on construction and automatically signals the semaphore on destruc...
Definition: psync.h:86
PWaitAndSignal::~PWaitAndSignal
~PWaitAndSignal()
Signal the semaphore.
Definition: psync.h:102
PSync::Wait
virtual void Wait()=0
Block until the synchronisation object is available.
PSyncNULL::Wait
virtual void Wait()
Block until the synchronisation object is available.
Definition: psync.h:63
PWaitAndSignal::PWaitAndSignal
PWaitAndSignal(const PSync &sem, PBoolean wait=true)
Create the semaphore wait instance.
Definition: psync.h:92
PSyncNULL::Signal
virtual void Signal()
Signal that the synchronisation object is available.
Definition: psync.h:64
PSync
Definition: psync.h:45
PBoolean
BOOL PBoolean
Definition: object.h:102
contain.h
PSyncNULL
Definition: psync.h:60
PSync::Signal
virtual void Signal()=0
Signal that the synchronisation object is available.
object.h
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PWaitAndSignal::sync
PSync & sync
Definition: psync.h:106