PTLib  Version 2.10.10
semaphor.h
Go to the documentation of this file.
1 /*
2  * semaphor.h
3  *
4  * Thread synchronisation semaphore class.
5  *
6  * Portable Tools Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 24177 $
30  * $Author: rjongbloed $
31  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
32  */
33 
34 #ifndef PTLIB_SEMAPHORE_H
35 #define PTLIB_SEMAPHORE_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <ptlib/psync.h>
42 #include <limits.h>
43 #include <ptlib/critsec.h>
44 
78 class PSemaphore : public PSync
79 {
80  PCLASSINFO(PSemaphore, PSync);
81 
82  public:
89  PSemaphore(
90  unsigned initial,
91  unsigned maximum
92  );
93 
96  PSemaphore(const PSemaphore &);
97 
101  ~PSemaphore();
103 
109  virtual void Wait();
110 
117  virtual PBoolean Wait(
118  const PTimeInterval & timeout // Amount of time to wait for semaphore.
119  );
120 
125  virtual void Signal();
126 
133  virtual PBoolean WillBlock() const;
135 
136  private:
137  PSemaphore & operator=(const PSemaphore &) { return *this; }
138 
139 
140 // Include platform dependent part of class
141 #ifdef _WIN32
142 #include "msos/ptlib/semaphor.h"
143 #else
144 #include "unix/ptlib/semaphor.h"
145 #endif
146 };
147 
148 
149 #endif // PTLIB_SEMAPHORE_H
150 
151 
152 // End Of File ///////////////////////////////////////////////////////////////
This class defines a thread synchronisation object.
Definition: semaphor.h:78
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
Definition: psync.h:45
virtual void Signal()
If there are waiting (blocked) threads then unblock the first one that was blocked.
BOOL PBoolean
Definition: object.h:102
virtual void Wait()
If the semaphore count is > 0, decrement the semaphore and return.
~PSemaphore()
Destroy the semaphore.
PSemaphore(unsigned initial, unsigned maximum)
Create a new semaphore with maximum count and initial value specified.
virtual PBoolean WillBlock() const
Determine if the semaphore would block if the Wait() function were called.