|
@@ -17,14 +17,104 @@
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
-// 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.
|
|
|
|
|
|
|
+#ifdef MUTEX_REENTRANT
|
|
|
|
|
+// In this branch, the ReMutex class is implemented as a thin wrapper
|
|
|
|
|
+// around the native MutexImpl class (which is already reentrant
|
|
|
|
|
+// anyway).
|
|
|
|
|
|
|
|
-#if !defined(THREAD_DUMMY_IMPL) || defined(CHECK_REENTRANT_MUTEX)
|
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+// Function: ReMutex::Constructor
|
|
|
|
|
+// Access: Public
|
|
|
|
|
+// Description:
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+INLINE ReMutex::
|
|
|
|
|
+ReMutex() {
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-// In this branch, the mutex is actually implemented.
|
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+// 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 MutexHolder.
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+INLINE void ReMutex::
|
|
|
|
|
+lock() const {
|
|
|
|
|
+ ((MutexImpl &)_impl).lock();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+// 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 {
|
|
|
|
|
+ ((MutexImpl &)_impl).release();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+// Function: ReMutex::debug_is_locked
|
|
|
|
|
+// Access: Public
|
|
|
|
|
+// Description: Returns true if the current thread has locked the
|
|
|
|
|
+// Mutex, false otherwise. This method is only
|
|
|
|
|
+// meaningful if CHECK_REENTRANT_MUTEX is defined;
|
|
|
|
|
+// otherwise, it always returns true.
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+INLINE bool ReMutex::
|
|
|
|
|
+debug_is_locked() const {
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#elif !defined(THREAD_DUMMY_IMPL) || defined(CHECK_REENTRANT_MUTEX)
|
|
|
|
|
+
|
|
|
|
|
+// In this branch, the ReMutex object is implemented as a heavy
|
|
|
|
|
+// wrapper around the Mutex and ConditionVar classes, to impose
|
|
|
|
|
+// reentrant semantics where the underlying MutexImpl doesn't provide
|
|
|
|
|
+// them.
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: ReMutex::Constructor
|
|
// Function: ReMutex::Constructor
|
|
@@ -103,46 +193,18 @@ release() const {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: ReMutex::is_locked
|
|
|
|
|
|
|
+// Function: ReMutex::debug_is_locked
|
|
|
// Access: Public
|
|
// Access: Public
|
|
|
// Description: Returns true if *this thread* already holds the lock,
|
|
// Description: Returns true if *this thread* already holds the lock,
|
|
|
// false if no one holds the lock or the lock is held by
|
|
// false if no one holds the lock or the lock is held by
|
|
|
// some other thread.
|
|
// some other thread.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
INLINE bool ReMutex::
|
|
INLINE bool ReMutex::
|
|
|
-is_locked() const {
|
|
|
|
|
|
|
+debug_is_locked() const {
|
|
|
MutexHolder holder(_mutex);
|
|
MutexHolder holder(_mutex);
|
|
|
return (_locking_thread == Thread::get_current_thread());
|
|
return (_locking_thread == Thread::get_current_thread());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
|
|
-// 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 {
|
|
|
|
|
- MutexHolder holder(_mutex);
|
|
|
|
|
- if (_locking_thread == Thread::get_current_thread()) {
|
|
|
|
|
- return _lock_count;
|
|
|
|
|
- }
|
|
|
|
|
- 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();
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
#else // !THREAD_DUMMY_IMPL || CHECK_REENTRANT_MUTEX
|
|
#else // !THREAD_DUMMY_IMPL || CHECK_REENTRANT_MUTEX
|
|
|
|
|
|
|
|
// In this branch, the mutex is stubbed out to do nothing.
|
|
// In this branch, the mutex is stubbed out to do nothing.
|
|
@@ -218,37 +280,13 @@ INLINE void ReMutex::
|
|
|
release() const {
|
|
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
|
|
// Function: ReMutex::debug_is_locked
|
|
|
// Access: Public
|
|
// 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).
|
|
|
|
|
|
|
+// Description: Returns true if the current thread has locked the
|
|
|
|
|
+// Mutex, false otherwise. This method is only
|
|
|
|
|
+// meaningful if CHECK_REENTRANT_MUTEX is defined;
|
|
|
|
|
+// otherwise, it always returns true.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
INLINE bool ReMutex::
|
|
INLINE bool ReMutex::
|
|
|
debug_is_locked() const {
|
|
debug_is_locked() const {
|
|
@@ -256,3 +294,4 @@ debug_is_locked() const {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endif // !THREAD_DUMMY_IMPL || CHECK_REENTRANT_MUTEX
|
|
#endif // !THREAD_DUMMY_IMPL || CHECK_REENTRANT_MUTEX
|
|
|
|
|
+
|