semaphor.h

Go to the documentation of this file.
00001 /*
00002  * semaphor.h
00003  *
00004  * Thread synchronisation semaphore class.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
00025  * All Rights Reserved.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Log: semaphor.h,v $
00030  * Revision 1.22  2007/09/05 11:58:47  csoutheren
00031  * Fixed build on MacOSX
00032  *
00033  * Revision 1.21  2005/11/25 03:43:47  csoutheren
00034  * Fixed function argument comments to be compatible with Doxygen
00035  *
00036  * Revision 1.20  2005/11/14 22:29:13  csoutheren
00037  * Reverted Wait and Signal to non-const - there is no way we can guarantee that all
00038  * descendant classes everywhere will be changed over, so we have to keep the
00039  * original  API
00040  *
00041  * Revision 1.19  2005/11/04 06:34:20  csoutheren
00042  * Added new class PSync as abstract base class for all mutex/sempahore classes
00043  * Changed PCriticalSection to use Wait/Signal rather than Enter/Leave
00044  * Changed Wait/Signal to be const member functions
00045  * Renamed PMutex to PTimedMutex and made PMutex synonym for PCriticalSection.
00046  * This allows use of very efficient mutex primitives in 99% of cases where timed waits
00047  * are not needed
00048  *
00049  * Revision 1.18  2003/09/17 05:41:59  csoutheren
00050  * Removed recursive includes
00051  *
00052  * Revision 1.17  2003/09/17 01:18:02  csoutheren
00053  * Removed recursive include file system and removed all references
00054  * to deprecated coooperative threading support
00055  *
00056  * Revision 1.16  2002/09/16 01:08:59  robertj
00057  * Added #define so can select if #pragma interface/implementation is used on
00058  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00059  *
00060  * Revision 1.15  2002/01/23 04:26:36  craigs
00061  * Added copy constructors for PSemaphore, PMutex and PSyncPoint to allow
00062  * use of default copy constructors for objects containing instances of
00063  * these classes
00064  *
00065  * Revision 1.14  2001/11/23 00:55:18  robertj
00066  * Changed PWaitAndSignal so works inside const functions.
00067  *
00068  * Revision 1.13  2001/06/01 04:00:21  yurik
00069  * Removed dependency on obsolete function
00070  *
00071  * Revision 1.12  2001/05/22 12:49:32  robertj
00072  * Did some seriously wierd rewrite of platform headers to eliminate the
00073  *   stupid GNU compiler warning about braces not matching.
00074  *
00075  * Revision 1.11  2001/04/23 00:34:29  robertj
00076  * Added ability for PWaitAndSignal to not wait on semaphore.
00077  *
00078  * Revision 1.10  2001/01/27 23:40:09  yurik
00079  * WinCE port-related - CreateEvent used instead of CreateSemaphore
00080  *
00081  * Revision 1.9  2000/12/19 22:20:26  dereks
00082  * Add video channel classes to connect to the PwLib PVideoInputDevice class.
00083  * Add PFakeVideoInput class to generate test images for video.
00084  *
00085  * Revision 1.8  1999/03/09 02:59:50  robertj
00086  * Changed comments to doc++ compatible documentation.
00087  *
00088  * Revision 1.7  1999/02/16 08:11:10  robertj
00089  * MSVC 6.0 compatibility changes.
00090  *
00091  * Revision 1.6  1998/11/19 05:17:37  robertj
00092  * Added PWaitAndSignal class for easier mutexing.
00093  *
00094  * Revision 1.5  1998/09/23 06:21:19  robertj
00095  * Added open source copyright license.
00096  *
00097  * Revision 1.4  1998/03/20 03:16:11  robertj
00098  * Added special classes for specific sepahores, PMutex and PSyncPoint.
00099  *
00100  * Revision 1.3  1995/12/10 11:34:50  robertj
00101  * Fixed incorrect order of parameters in semaphore constructor.
00102  *
00103  * Revision 1.2  1995/11/21 11:49:42  robertj
00104  * Added timeout on semaphore wait.
00105  *
00106  * Revision 1.1  1995/08/01 21:41:24  robertj
00107  * Initial revision
00108  *
00109  */
00110 
00111 #ifndef _PSEMAPHORE
00112 #define _PSEMAPHORE
00113 
00114 #ifdef P_USE_PRAGMA
00115 #pragma interface
00116 #endif
00117 
00118 #include <ptlib/psync.h>
00119 #include <limits.h>
00120 #include <ptlib/critsec.h>
00121 
00155 class PSemaphore : public PSync
00156 {
00157   PCLASSINFO(PSemaphore, PSync);
00158 
00159   public:
00166     PSemaphore(
00167       unsigned initial, 
00168       unsigned maximum  
00169     );
00170 
00173     PSemaphore(const PSemaphore &);
00174 
00178     ~PSemaphore();
00180 
00186     virtual void Wait();
00187 
00194     virtual BOOL Wait(
00195       const PTimeInterval & timeout // Amount of time to wait for semaphore.
00196     );
00197 
00202     virtual void Signal();
00203 
00210     virtual BOOL WillBlock() const;
00212 
00213   private:
00214     PSemaphore & operator=(const PSemaphore &) { return *this; }
00215 
00216 
00217 // Include platform dependent part of class
00218 #ifdef _WIN32
00219 #include "msos/ptlib/semaphor.h"
00220 #else
00221 #include "unix/ptlib/semaphor.h"
00222 #endif
00223 };
00224 
00225 #endif
00226 
00227 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1