Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

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.18  2003/09/17 05:41:59  csoutheren
00031  * Removed recursive includes
00032  *
00033  * Revision 1.17  2003/09/17 01:18:02  csoutheren
00034  * Removed recursive include file system and removed all references
00035  * to deprecated coooperative threading support
00036  *
00037  * Revision 1.16  2002/09/16 01:08:59  robertj
00038  * Added #define so can select if #pragma interface/implementation is used on
00039  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00040  *
00041  * Revision 1.15  2002/01/23 04:26:36  craigs
00042  * Added copy constructors for PSemaphore, PMutex and PSyncPoint to allow
00043  * use of default copy constructors for objects containing instances of
00044  * these classes
00045  *
00046  * Revision 1.14  2001/11/23 00:55:18  robertj
00047  * Changed PWaitAndSignal so works inside const functions.
00048  *
00049  * Revision 1.13  2001/06/01 04:00:21  yurik
00050  * Removed dependency on obsolete function
00051  *
00052  * Revision 1.12  2001/05/22 12:49:32  robertj
00053  * Did some seriously wierd rewrite of platform headers to eliminate the
00054  *   stupid GNU compiler warning about braces not matching.
00055  *
00056  * Revision 1.11  2001/04/23 00:34:29  robertj
00057  * Added ability for PWaitAndSignal to not wait on semaphore.
00058  *
00059  * Revision 1.10  2001/01/27 23:40:09  yurik
00060  * WinCE port-related - CreateEvent used instead of CreateSemaphore
00061  *
00062  * Revision 1.9  2000/12/19 22:20:26  dereks
00063  * Add video channel classes to connect to the PwLib PVideoInputDevice class.
00064  * Add PFakeVideoInput class to generate test images for video.
00065  *
00066  * Revision 1.8  1999/03/09 02:59:50  robertj
00067  * Changed comments to doc++ compatible documentation.
00068  *
00069  * Revision 1.7  1999/02/16 08:11:10  robertj
00070  * MSVC 6.0 compatibility changes.
00071  *
00072  * Revision 1.6  1998/11/19 05:17:37  robertj
00073  * Added PWaitAndSignal class for easier mutexing.
00074  *
00075  * Revision 1.5  1998/09/23 06:21:19  robertj
00076  * Added open source copyright license.
00077  *
00078  * Revision 1.4  1998/03/20 03:16:11  robertj
00079  * Added special classes for specific sepahores, PMutex and PSyncPoint.
00080  *
00081  * Revision 1.3  1995/12/10 11:34:50  robertj
00082  * Fixed incorrect order of parameters in semaphore constructor.
00083  *
00084  * Revision 1.2  1995/11/21 11:49:42  robertj
00085  * Added timeout on semaphore wait.
00086  *
00087  * Revision 1.1  1995/08/01 21:41:24  robertj
00088  * Initial revision
00089  *
00090  */
00091 
00092 #ifndef _PSEMAPHORE
00093 #define _PSEMAPHORE
00094 
00095 #ifdef P_USE_PRAGMA
00096 #pragma interface
00097 #endif
00098 
00099 #include <limits.h>
00100 
00101 
00120 class PWaitAndSignal {
00121   public:
00126     PWaitAndSignal(
00127       const PSemaphore & sem,   
00128       BOOL wait = TRUE    
00129     );
00134     ~PWaitAndSignal();
00135 
00136   protected:
00137     PSemaphore & semaphore;
00138 };
00139 
00140 
00174 class PSemaphore : public PObject
00175 {
00176   PCLASSINFO(PSemaphore, PObject);
00177 
00178   public:
00185     PSemaphore(
00186       unsigned initial, 
00187       unsigned maximum  
00188     );
00189 
00192     PSemaphore(const PSemaphore &);
00193 
00197     ~PSemaphore();
00199 
00205     virtual void Wait();
00206 
00213     virtual BOOL Wait(
00214       const PTimeInterval & timeout // Amount of time to wait for semaphore.
00215     );
00216 
00221     virtual void Signal();
00222 
00229     virtual BOOL WillBlock() const;
00231 
00232   private:
00233     PSemaphore & operator=(const PSemaphore &) { return *this; }
00234 
00235 
00236 // Include platform dependent part of class
00237 #ifdef _WIN32
00238 #include "msos/ptlib/semaphor.h"
00239 #else
00240 #include "unix/ptlib/semaphor.h"
00241 #endif
00242 };
00243 
00244 #endif
00245 
00246 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 21 20:43:09 2005 for PWLib by  doxygen 1.4.1