Panda3D
 All Classes Functions Variables Enumerations
mutexPosixImpl.h
1 // Filename: mutexPosixImpl.h
2 // Created by: drose (10Feb06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef MUTEXPOSIXIMPL_H
16 #define MUTEXPOSIXIMPL_H
17 
18 #include "dtoolbase.h"
19 #include "selectThreadImpl.h"
20 
21 #ifdef HAVE_POSIX_THREADS
22 
23 #include <pthread.h>
24 #include <errno.h>
25 #include <assert.h>
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : MutexPosixImpl
29 // Description : Uses Posix threads to implement a mutex.
30 ////////////////////////////////////////////////////////////////////
31 class EXPCL_DTOOL MutexPosixImpl {
32 public:
33  INLINE MutexPosixImpl();
34  INLINE ~MutexPosixImpl();
35 
36  INLINE void acquire();
37  INLINE bool try_acquire();
38  INLINE void release();
39 
40  INLINE pthread_mutex_t *get_posix_lock();
41 
42 private:
43  pthread_mutex_t _lock;
44  friend class ConditionVarPosixImpl;
45 };
46 
47 ////////////////////////////////////////////////////////////////////
48 // Class : ReMutexPosixImpl
49 // Description : Uses Posix threads to implement a reentrant mutex.
50 ////////////////////////////////////////////////////////////////////
51 class EXPCL_DTOOL ReMutexPosixImpl {
52 public:
53  INLINE ReMutexPosixImpl();
54  INLINE ~ReMutexPosixImpl();
55 
56  INLINE void acquire();
57  INLINE bool try_acquire();
58  INLINE void release();
59 
60  INLINE pthread_mutex_t *get_posix_lock();
61 
62 private:
63  pthread_mutex_t _lock;
64 };
65 
66 #include "mutexPosixImpl.I"
67 
68 #endif // HAVE_POSIX_THREADS
69 
70 #endif