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.21 2005/11/25 03:43:47 csoutheren 00031 * Fixed function argument comments to be compatible with Doxygen 00032 * 00033 * Revision 1.20 2005/11/14 22:29:13 csoutheren 00034 * Reverted Wait and Signal to non-const - there is no way we can guarantee that all 00035 * descendant classes everywhere will be changed over, so we have to keep the 00036 * original API 00037 * 00038 * Revision 1.19 2005/11/04 06:34:20 csoutheren 00039 * Added new class PSync as abstract base class for all mutex/sempahore classes 00040 * Changed PCriticalSection to use Wait/Signal rather than Enter/Leave 00041 * Changed Wait/Signal to be const member functions 00042 * Renamed PMutex to PTimedMutex and made PMutex synonym for PCriticalSection. 00043 * This allows use of very efficient mutex primitives in 99% of cases where timed waits 00044 * are not needed 00045 * 00046 * Revision 1.18 2003/09/17 05:41:59 csoutheren 00047 * Removed recursive includes 00048 * 00049 * Revision 1.17 2003/09/17 01:18:02 csoutheren 00050 * Removed recursive include file system and removed all references 00051 * to deprecated coooperative threading support 00052 * 00053 * Revision 1.16 2002/09/16 01:08:59 robertj 00054 * Added #define so can select if #pragma interface/implementation is used on 00055 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00056 * 00057 * Revision 1.15 2002/01/23 04:26:36 craigs 00058 * Added copy constructors for PSemaphore, PMutex and PSyncPoint to allow 00059 * use of default copy constructors for objects containing instances of 00060 * these classes 00061 * 00062 * Revision 1.14 2001/11/23 00:55:18 robertj 00063 * Changed PWaitAndSignal so works inside const functions. 00064 * 00065 * Revision 1.13 2001/06/01 04:00:21 yurik 00066 * Removed dependency on obsolete function 00067 * 00068 * Revision 1.12 2001/05/22 12:49:32 robertj 00069 * Did some seriously wierd rewrite of platform headers to eliminate the 00070 * stupid GNU compiler warning about braces not matching. 00071 * 00072 * Revision 1.11 2001/04/23 00:34:29 robertj 00073 * Added ability for PWaitAndSignal to not wait on semaphore. 00074 * 00075 * Revision 1.10 2001/01/27 23:40:09 yurik 00076 * WinCE port-related - CreateEvent used instead of CreateSemaphore 00077 * 00078 * Revision 1.9 2000/12/19 22:20:26 dereks 00079 * Add video channel classes to connect to the PwLib PVideoInputDevice class. 00080 * Add PFakeVideoInput class to generate test images for video. 00081 * 00082 * Revision 1.8 1999/03/09 02:59:50 robertj 00083 * Changed comments to doc++ compatible documentation. 00084 * 00085 * Revision 1.7 1999/02/16 08:11:10 robertj 00086 * MSVC 6.0 compatibility changes. 00087 * 00088 * Revision 1.6 1998/11/19 05:17:37 robertj 00089 * Added PWaitAndSignal class for easier mutexing. 00090 * 00091 * Revision 1.5 1998/09/23 06:21:19 robertj 00092 * Added open source copyright license. 00093 * 00094 * Revision 1.4 1998/03/20 03:16:11 robertj 00095 * Added special classes for specific sepahores, PMutex and PSyncPoint. 00096 * 00097 * Revision 1.3 1995/12/10 11:34:50 robertj 00098 * Fixed incorrect order of parameters in semaphore constructor. 00099 * 00100 * Revision 1.2 1995/11/21 11:49:42 robertj 00101 * Added timeout on semaphore wait. 00102 * 00103 * Revision 1.1 1995/08/01 21:41:24 robertj 00104 * Initial revision 00105 * 00106 */ 00107 00108 #ifndef _PSEMAPHORE 00109 #define _PSEMAPHORE 00110 00111 #ifdef P_USE_PRAGMA 00112 #pragma interface 00113 #endif 00114 00115 #include <ptlib/psync.h> 00116 #include <limits.h> 00117 00151 class PSemaphore : public PSync 00152 { 00153 PCLASSINFO(PSemaphore, PSync); 00154 00155 public: 00162 PSemaphore( 00163 unsigned initial, 00164 unsigned maximum 00165 ); 00166 00169 PSemaphore(const PSemaphore &); 00170 00174 ~PSemaphore(); 00176 00182 virtual void Wait(); 00183 00190 virtual BOOL Wait( 00191 const PTimeInterval & timeout // Amount of time to wait for semaphore. 00192 ); 00193 00198 virtual void Signal(); 00199 00206 virtual BOOL WillBlock() const; 00208 00209 private: 00210 PSemaphore & operator=(const PSemaphore &) { return *this; } 00211 00212 00213 // Include platform dependent part of class 00214 #ifdef _WIN32 00215 #include "msos/ptlib/semaphor.h" 00216 #else 00217 #include "unix/ptlib/semaphor.h" 00218 #endif 00219 }; 00220 00221 #endif 00222 00223 // End Of File ///////////////////////////////////////////////////////////////