00001 #ifndef __J2K__PThread_RecursiveMutex_HPP__ 00002 #define __J2K__PThread_RecursiveMutex_HPP__ 00003 00004 /* 00005 * A mutex for synchronizing recursive methods. 00006 * Use a Lock to lock and unlock a RecursiveMutex. 00007 * 00008 * If a locked RecursiveMutex is locked again by the same thread, 00009 * its lock count is incremented. If it unlocked by the same 00010 * thread, its lock count is decremented. When its lock count 00011 * reaches 0, it is unlocked. 00012 * 00013 * This class is not reference-counted; each instance is intended to be 00014 * encapsulated as a member variable by the object that uses it. 00015 */ 00016 00017 #include <j2k/Fred/PThread/Mutex.hpp> 00018 00019 class RecursiveMutex : public Mutex { 00020 public: 00021 RecursiveMutex(); 00022 virtual ~RecursiveMutex(); 00023 00024 protected: 00025 virtual void lock(); 00026 virtual void unlock(); 00027 virtual void wait(); 00028 00029 private: 00030 RecursiveMutex(const RecursiveMutex& src ); 00031 RecursiveMutex& operator=(const RecursiveMutex& right); 00032 00033 private: 00034 unsigned int lockCount; 00035 pthread_t owner; 00036 }; 00037 00038 #endif