Panda3D
|
00001 // Filename: mutexPosixImpl.h 00002 // Created by: drose (10Feb06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef MUTEXPOSIXIMPL_H 00016 #define MUTEXPOSIXIMPL_H 00017 00018 #include "dtoolbase.h" 00019 #include "selectThreadImpl.h" 00020 00021 #ifdef HAVE_POSIX_THREADS 00022 00023 #include <pthread.h> 00024 #include <errno.h> 00025 #include <assert.h> 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : MutexPosixImpl 00029 // Description : Uses Posix threads to implement a mutex. 00030 //////////////////////////////////////////////////////////////////// 00031 class EXPCL_DTOOL MutexPosixImpl { 00032 public: 00033 INLINE MutexPosixImpl(); 00034 INLINE ~MutexPosixImpl(); 00035 00036 INLINE void acquire(); 00037 INLINE bool try_acquire(); 00038 INLINE void release(); 00039 00040 INLINE pthread_mutex_t *get_posix_lock(); 00041 00042 private: 00043 pthread_mutex_t _lock; 00044 friend class ConditionVarPosixImpl; 00045 }; 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Class : ReMutexPosixImpl 00049 // Description : Uses Posix threads to implement a reentrant mutex. 00050 //////////////////////////////////////////////////////////////////// 00051 class EXPCL_DTOOL ReMutexPosixImpl { 00052 public: 00053 INLINE ReMutexPosixImpl(); 00054 INLINE ~ReMutexPosixImpl(); 00055 00056 INLINE void acquire(); 00057 INLINE bool try_acquire(); 00058 INLINE void release(); 00059 00060 INLINE pthread_mutex_t *get_posix_lock(); 00061 00062 private: 00063 pthread_mutex_t _lock; 00064 }; 00065 00066 #include "mutexPosixImpl.I" 00067 00068 #endif // HAVE_POSIX_THREADS 00069 00070 #endif