00001 /* 00002 * psync.h 00003 * 00004 * Abstract synchronisation semaphore class. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-1998 Equivalence Pty. Ltd. 00009 * Copyright (c) 2005 Post Increment 00010 * 00011 * The contents of this file are subject to the Mozilla Public License 00012 * Version 1.0 (the "License"); you may not use this file except in 00013 * compliance with the License. You may obtain a copy of the License at 00014 * http://www.mozilla.org/MPL/ 00015 * 00016 * Software distributed under the License is distributed on an "AS IS" 00017 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00018 * the License for the specific language governing rights and limitations 00019 * under the License. 00020 * 00021 * The Original Code is Portable Windows Library. 00022 * 00023 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00024 * 00025 * Portions are Copyright (C) 1993 Free Software Foundation, Inc. 00026 * All Rights Reserved. 00027 * 00028 * Contributor(s): ______________________________________. 00029 * 00030 * $Log: psync.h,v $ 00031 * Revision 1.4 2005/11/25 03:43:47 csoutheren 00032 * Fixed function argument comments to be compatible with Doxygen 00033 * 00034 * Revision 1.3 2005/11/14 22:29:13 csoutheren 00035 * Reverted Wait and Signal to non-const - there is no way we can guarantee that all 00036 * descendant classes everywhere will be changed over, so we have to keep the 00037 * original API 00038 * 00039 * Revision 1.2 2005/11/04 06:56:10 csoutheren 00040 * Added new class PSync as abstract base class for all mutex/sempahore classes 00041 * Changed PCriticalSection to use Wait/Signal rather than Enter/Leave 00042 * Changed Wait/Signal to be const member functions 00043 * Renamed PMutex to PTimedMutex and made PMutex synonym for PCriticalSection. 00044 * This allows use of very efficient mutex primitives in 99% of cases where timed waits 00045 * are not needed 00046 * 00047 * Revision 1.1 2005/11/04 06:34:20 csoutheren 00048 * Added new class PSync as abstract base class for all mutex/sempahore classes 00049 * Changed PCriticalSection to use Wait/Signal rather than Enter/Leave 00050 * Changed Wait/Signal to be const member functions 00051 * Renamed PMutex to PTimedMutex and made PMutex synonym for PCriticalSection. 00052 * This allows use of very efficient mutex primitives in 99% of cases where timed waits 00053 * are not needed 00054 * 00055 */ 00056 00057 #ifndef _PSYNC 00058 #define _PSYNC 00059 00060 #ifdef P_USE_PRAGMA 00061 #pragma interface 00062 #endif 00063 00064 #include <ptlib/contain.h> 00065 00066 class PSync : public PObject 00067 { 00068 public: 00073 virtual void Wait() = 0; 00074 00077 virtual void Signal() = 0; 00079 00080 }; 00081 00101 class PWaitAndSignal { 00102 public: 00107 inline PWaitAndSignal( 00108 const PSync & sem, 00109 BOOL wait = TRUE 00110 ) : sync((PSync &)sem) 00111 { if (wait) sync.Wait(); } 00112 00117 ~PWaitAndSignal() 00118 { sync.Signal(); } 00119 00120 protected: 00121 PSync & sync; 00122 }; 00123 00124 #endif // PSYNC 00125