From 273f091ecc0f5dd31d4d60a65b5f84c302bfef5e Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 18 Jan 2006 23:55:11 +0000 Subject: [PATCH] more mutex fixes --- panda/src/express/reMutex.I | 125 ++++++++++++++++++++++++++- panda/src/express/reMutex.cxx | 9 ++ panda/src/express/reMutex.h | 10 +-- panda/src/express/threadNsprImpl.cxx | 1 + 4 files changed, 138 insertions(+), 7 deletions(-) diff --git a/panda/src/express/reMutex.I b/panda/src/express/reMutex.I index 2b4a224929..7074ee16cb 100644 --- a/panda/src/express/reMutex.I +++ b/panda/src/express/reMutex.I @@ -17,6 +17,15 @@ //////////////////////////////////////////////////////////////////// +// Most of the methods in this class are stubbed out in the +// THREAD_DUMMY_IMPL case, especially when CHECK_REENTRANT_MUTEX is +// not defined. In this case, we're not performing any actual locking +// or verification, so there's no need to do anything at all here. + +#if !defined(THREAD_DUMMY_IMPL) || defined(CHECK_REENTRANT_MUTEX) + +// In this branch, the mutex is actually implemented. + //////////////////////////////////////////////////////////////////// // Function: ReMutex::Constructor // Access: Public @@ -122,7 +131,6 @@ get_lock_count() const { return 0; } -#ifndef NDEBUG //////////////////////////////////////////////////////////////////// // Function: ReMutex::debug_is_locked // Access: Public @@ -134,4 +142,117 @@ INLINE bool ReMutex:: debug_is_locked() const { return is_locked(); } -#endif // NDEBUG + +#else // !THREAD_DUMMY_IMPL || CHECK_REENTRANT_MUTEX + +// In this branch, the mutex is stubbed out to do nothing. + +//////////////////////////////////////////////////////////////////// +// Function: ReMutex::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE ReMutex:: +ReMutex() { +} + +//////////////////////////////////////////////////////////////////// +// Function: ReMutex::Destructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE ReMutex:: +~ReMutex() { +} + +//////////////////////////////////////////////////////////////////// +// Function: ReMutex::Copy Constructor +// Access: Private +// Description: Do not attempt to copy mutexes. +//////////////////////////////////////////////////////////////////// +INLINE ReMutex:: +ReMutex(const ReMutex ©) { + nassertv(false); +} + +//////////////////////////////////////////////////////////////////// +// Function: ReMutex::Copy Assignment Operator +// Access: Private +// Description: Do not attempt to copy mutexes. +//////////////////////////////////////////////////////////////////// +INLINE void ReMutex:: +operator = (const ReMutex ©) { + nassertv(false); +} + +//////////////////////////////////////////////////////////////////// +// Function: ReMutex::lock +// Access: Public +// Description: Grabs the mutex if it is available. If it is not +// available, blocks until it becomes available, then +// grabs it. In either case, the function does not +// return until the mutex is held; you should then call +// unlock(). +// +// This method is considered const so that you can lock +// and unlock const mutexes, mainly to allow thread-safe +// access to otherwise const data. +// +// Also see ReMutexHolder. +//////////////////////////////////////////////////////////////////// +INLINE void ReMutex:: +lock() const { +} + +//////////////////////////////////////////////////////////////////// +// Function: ReMutex::release +// Access: Public +// Description: Releases the mutex. It is an error to call this if +// the mutex was not already locked. +// +// This method is considered const so that you can lock +// and unlock const mutexes, mainly to allow thread-safe +// access to otherwise const data. +//////////////////////////////////////////////////////////////////// +INLINE void ReMutex:: +release() const { +} + +//////////////////////////////////////////////////////////////////// +// Function: ReMutex::is_locked +// Access: Public +// Description: Returns true if *this thread* already holds the lock, +// false if no one holds the lock or the lock is held by +// some other thread. +//////////////////////////////////////////////////////////////////// +INLINE bool ReMutex:: +is_locked() const { + // In the stub version, this method always returns true. + return true; +} + +//////////////////////////////////////////////////////////////////// +// Function: ReMutex::get_lock_count +// Access: Public +// Description: Returns the number of times that *this thread* has +// grabbed the lock. Returns 0 if some other thread is +// currently holding the lock. +//////////////////////////////////////////////////////////////////// +INLINE int ReMutex:: +get_lock_count() const { + return 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: ReMutex::debug_is_locked +// Access: Public +// Description: The same as is_locked(). This method name is +// provided just to maintain symmetry with Mutex (which +// doesn't provide an is_locked() method). +//////////////////////////////////////////////////////////////////// +INLINE bool ReMutex:: +debug_is_locked() const { + return is_locked(); +} + +#endif // !THREAD_DUMMY_IMPL || CHECK_REENTRANT_MUTEX diff --git a/panda/src/express/reMutex.cxx b/panda/src/express/reMutex.cxx index 57da78c2bf..7d885e3056 100644 --- a/panda/src/express/reMutex.cxx +++ b/panda/src/express/reMutex.cxx @@ -18,6 +18,13 @@ #include "reMutex.h" +// Most of the methods in this class are stubbed out in the +// THREAD_DUMMY_IMPL case, especially when CHECK_REENTRANT_MUTEX is +// not defined. In this case, we're not performing any actual locking +// or verification, so there's no need to do anything at all here. + +#if !defined(THREAD_DUMMY_IMPL) || defined(CHECK_REENTRANT_MUTEX) + //////////////////////////////////////////////////////////////////// // Function: ReMutex::do_lock // Access: Private @@ -69,3 +76,5 @@ do_release() { _cvar.signal(); } } + +#endif // !THREAD_DUMMY_IMPL || CHECK_REENTRANT_MUTEX diff --git a/panda/src/express/reMutex.h b/panda/src/express/reMutex.h index a585f3ab0b..54a3118abd 100644 --- a/panda/src/express/reMutex.h +++ b/panda/src/express/reMutex.h @@ -29,9 +29,9 @@ //////////////////////////////////////////////////////////////////// // Class : ReMutex // Description : A reentrant mutex. This kind of mutex can be locked -// again by the thread that already holds it, without -// deadlock. The thread must eventually release the -// mutex the same number of times it locked it. +// more than once by the thread that already holds it, +// without deadlock. The thread must eventually release +// the mutex the same number of times it locked it. //////////////////////////////////////////////////////////////////// class EXPCL_PANDAEXPRESS ReMutex { public: @@ -48,11 +48,10 @@ public: INLINE bool is_locked() const; INLINE int get_lock_count() const; -#ifndef NDEBUG INLINE bool debug_is_locked() const; -#endif private: +#if !defined(THREAD_DUMMY_IMPL) || defined(CHECK_REENTRANT_MUTEX) void do_lock(); void do_release(); @@ -60,6 +59,7 @@ private: ConditionVar _cvar; Thread *_locking_thread; int _lock_count; +#endif // !THREAD_DUMMY_IMPL || CHECK_REENTRANT_MUTEX }; #include "reMutex.I" diff --git a/panda/src/express/threadNsprImpl.cxx b/panda/src/express/threadNsprImpl.cxx index 78e163fa56..99fb77ec72 100644 --- a/panda/src/express/threadNsprImpl.cxx +++ b/panda/src/express/threadNsprImpl.cxx @@ -121,6 +121,7 @@ start(ThreadPriority priority, bool global, bool joinable) { default: nassertr(false, false); + nspr_pri = PR_PRIORITY_NORMAL; } PRThreadScope nspr_scope = (global) ? PR_GLOBAL_THREAD : PR_LOCAL_THREAD;