PTLib  Version 2.10.11
psync.h
Go to the documentation of this file.
1 /*
2  * psync.h
3  *
4  * Abstract synchronisation semaphore class.
5  *
6  * Portable Tools Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  * Copyright (c) 2005 Post Increment
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Portable Windows Library.
22  *
23  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24  *
25  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
26  * All Rights Reserved.
27  *
28  * Contributor(s): ______________________________________.
29  *
30  * $Revision: 27923 $
31  * $Author: rjongbloed $
32  * $Date: 2012-06-27 22:28:36 -0500 (Wed, 27 Jun 2012) $
33  */
34 
35 #ifndef PTLIB_SYNC_H
36 #define PTLIB_SYNC_H
37 
38 #ifdef P_USE_PRAGMA
39 #pragma interface
40 #endif
41 
42 #include <ptlib/contain.h>
43 #include <ptlib/object.h>
44 
45 class PSync : public PObject
46 {
47  public:
52  virtual void Wait() = 0;
53 
56  virtual void Signal() = 0;
58 };
59 
60 class PSyncNULL : public PSync
61 {
62  public:
63  virtual void Wait() { }
64  virtual void Signal() { }
65 };
66 
87  public:
93  const PSync & sem,
94  PBoolean wait = true
95  ) : sync((PSync &)sem)
96  { if (wait) sync.Wait(); }
97 
103  { sync.Signal(); }
104 
105  protected:
107 };
108 
109 
110 #endif // PTLIB_SYNC_H
111 
112 
113 // End Of File ///////////////////////////////////////////////////////////////
This class waits for the semaphore on construction and automatically signals the semaphore on destruc...
Definition: psync.h:86
~PWaitAndSignal()
Signal the semaphore.
Definition: psync.h:102
virtual void Wait()=0
Block until the synchronisation object is available.
virtual void Wait()
Block until the synchronisation object is available.
Definition: psync.h:63
PWaitAndSignal(const PSync &sem, PBoolean wait=true)
Create the semaphore wait instance.
Definition: psync.h:92
virtual void Signal()
Signal that the synchronisation object is available.
Definition: psync.h:64
Definition: psync.h:45
BOOL PBoolean
Definition: object.h:102
Definition: psync.h:60
virtual void Signal()=0
Signal that the synchronisation object is available.
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PSync & sync
Definition: psync.h:106