PTLib  Version 2.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mutex.h
Go to the documentation of this file.
1 /*
2  * mutex.h
3  *
4  * Mutual exclusion thread synchonisation class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 24177 $
30  * $Author: rjongbloed $
31  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
32  */
33 
34 #ifndef PTLIB_MUTEX_H
35 #define PTLIB_MUTEX_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <ptlib/critsec.h>
42 #include <ptlib/semaphor.h>
43 
65 /*
66  * On Windows, It is convenient for PTimedMutex to be an ancestor of PSemaphore
67  * But that is the only platform where it is - every other platform (i.e. Unix)
68  * uses different constructs for these objects, so there is no need for a PTimedMute
69  * to carry around all of the PSemaphore members
70  */
71 
72 #ifdef _WIN32
73 class PTimedMutex : public PSemaphore
74 {
76 #else
77 class PTimedMutex : public PSync
78 {
80 #endif
81 
82  public:
83  /* Create a new mutex.
84  Initially the mutex will not be "set", so the first call to Wait() will
85  never wait.
86  */
87  PTimedMutex();
88  PTimedMutex(const PTimedMutex & mutex);
89 
93  PINLINE bool Try() { return Wait(0); }
94 
95 // Include platform dependent part of class
96 #ifdef _WIN32
97 #include "msos/ptlib/mutex.h"
98 #else
99 #include "unix/ptlib/mutex.h"
100 #endif
101 };
102 
103 // On Windows, critical sections are recursive and so we can use them for mutexes
104 // The only Posix mutex that is recursive is pthread_mutex, so we have to use that
105 #ifdef _WIN32
106 
109 typedef PCriticalSection PMutex;
110 #else
111 
115 #define PCriticalSection PTimedMutex
116 #endif
117 
118 
119 #endif // PTLIB_MUTEX_H
120 
121 
122 // End Of File ///////////////////////////////////////////////////////////////