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