00001 /* 00002 * mutex.h 00003 * 00004 * Mutual exclusion thread synchonisation 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: mutex.h,v $ 00030 * Revision 1.16 2007/09/05 11:58:47 csoutheren 00031 * Fixed build on MacOSX 00032 * 00033 * Revision 1.15 2007/09/05 11:09:09 csoutheren 00034 * Removed misleading and incorrect code from Linux implementation of 00035 * PCriticalSection. Apologies to Hannes Friederich :( 00036 * 00037 * Revision 1.14 2005/11/25 00:06:12 csoutheren 00038 * Applied patch #1364593 from Hannes Friederich 00039 * Also changed so PTimesMutex is no longer descended from PSemaphore on 00040 * non-Windows platforms 00041 * 00042 * Revision 1.13 2005/11/08 22:31:00 csoutheren 00043 * Moved declaration of PMutex 00044 * 00045 * Revision 1.12 2005/11/08 22:18:31 csoutheren 00046 * Changed PMutex to use PTimedMutex on non-Windows platforms because 00047 * sem_wait is not recursive. Very sad. 00048 * Thanks to Frederic Heem for finding this problem 00049 * 00050 * Revision 1.11 2005/11/04 06:34:20 csoutheren 00051 * Added new class PSync as abstract base class for all mutex/sempahore classes 00052 * Changed PCriticalSection to use Wait/Signal rather than Enter/Leave 00053 * Changed Wait/Signal to be const member functions 00054 * Renamed PMutex to PTimedMutex and made PMutex synonym for PCriticalSection. 00055 * This allows use of very efficient mutex primitives in 99% of cases where timed waits 00056 * are not needed 00057 * 00058 * Revision 1.10 2003/09/17 05:41:58 csoutheren 00059 * Removed recursive includes 00060 * 00061 * Revision 1.9 2003/09/17 01:18:02 csoutheren 00062 * Removed recursive include file system and removed all references 00063 * to deprecated coooperative threading support 00064 * 00065 * Revision 1.8 2002/09/16 01:08:59 robertj 00066 * Added #define so can select if #pragma interface/implementation is used on 00067 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00068 * 00069 * Revision 1.7 2002/01/23 04:26:36 craigs 00070 * Added copy constructors for PSemaphore, PMutex and PSyncPoint to allow 00071 * use of default copy constructors for objects containing instances of 00072 * these classes 00073 * 00074 * Revision 1.6 2001/05/22 12:49:32 robertj 00075 * Did some seriously wierd rewrite of platform headers to eliminate the 00076 * stupid GNU compiler warning about braces not matching. 00077 * 00078 * Revision 1.5 1999/03/09 02:59:50 robertj 00079 * Changed comments to doc++ compatible documentation. 00080 * 00081 * Revision 1.4 1999/02/16 08:12:22 robertj 00082 * MSVC 6.0 compatibility changes. 00083 * 00084 * Revision 1.3 1998/11/30 02:50:59 robertj 00085 * New directory structure 00086 * 00087 * Revision 1.2 1998/09/23 06:20:55 robertj 00088 * Added open source copyright license. 00089 * 00090 * Revision 1.1 1998/03/23 02:41:31 robertj 00091 * Initial revision 00092 * 00093 */ 00094 00095 #ifndef _PMUTEX 00096 #define _PMUTEX 00097 00098 #ifdef P_USE_PRAGMA 00099 #pragma interface 00100 #endif 00101 00102 #include <ptlib/critsec.h> 00103 #include <ptlib/semaphor.h> 00104 00126 /* 00127 * On Windows, It is convenient for PTimedMutex to be an ancestor of PSemaphore 00128 * But that is the only platform where it is - every other platform (i.e. Unix) 00129 * uses different constructs for these objects, so there is no need for a PTimedMute 00130 * to carry around all of the PSemaphore members 00131 */ 00132 00133 #ifdef _WIN32 00134 class PTimedMutex : public PSemaphore 00135 { 00136 PCLASSINFO(PTimedMutex, PSemaphore); 00137 #else 00138 class PTimedMutex : public PSync 00139 { 00140 PCLASSINFO(PTimedMutex, PSync) 00141 #endif 00142 00143 public: 00144 /* Create a new mutex. 00145 Initially the mutex will not be "set", so the first call to Wait() will 00146 never wait. 00147 */ 00148 PTimedMutex(); 00149 PTimedMutex(const PTimedMutex & mutex); 00150 00151 // Include platform dependent part of class 00152 #ifdef _WIN32 00153 #include "msos/ptlib/mutex.h" 00154 #else 00155 #include "unix/ptlib/mutex.h" 00156 #endif 00157 }; 00158 00159 // On Windows, critical sections are recursive and so we can use them for mutexes 00160 // The only Posix mutex that is recursive is pthread_mutex, so we have to use that 00161 #ifdef _WIN32 00162 typedef PCriticalSection PMutex; 00163 #else 00164 typedef PTimedMutex PMutex; 00165 #define PCriticalSection PTimedMutex 00166 #endif 00167 00168 #endif 00169 00170 // End Of File ///////////////////////////////////////////////////////////////