Kaynağa Gözat

assert non-reentrancy in non-threads case

David Rose 20 yıl önce
ebeveyn
işleme
bac632973c

+ 3 - 3
panda/src/express/mutexHolder.I

@@ -24,7 +24,7 @@
 ////////////////////////////////////////////////////////////////////
 INLINE MutexHolder::
 MutexHolder(const Mutex &mutex) {
-#ifdef HAVE_THREADS
+#if defined(HAVE_THREADS) || !defined(NDEBUG)
   _mutex = &mutex;
   _mutex->lock();
 #endif
@@ -43,7 +43,7 @@ MutexHolder(const Mutex &mutex) {
 ////////////////////////////////////////////////////////////////////
 INLINE MutexHolder::
 MutexHolder(Mutex *&mutex) {
-#ifdef HAVE_THREADS
+#if defined(HAVE_THREADS) || !defined(NDEBUG)
   if (mutex == (Mutex *)NULL) {
     mutex = new Mutex;
   }
@@ -59,7 +59,7 @@ MutexHolder(Mutex *&mutex) {
 ////////////////////////////////////////////////////////////////////
 INLINE MutexHolder::
 ~MutexHolder() {
-#ifdef HAVE_THREADS
+#if defined(HAVE_THREADS) || !defined(NDEBUG)
   _mutex->release();
 #endif
 }

+ 7 - 1
panda/src/express/mutexHolder.h

@@ -40,7 +40,13 @@ private:
   INLINE void operator = (const MutexHolder &copy);
 
 private:
-#ifdef HAVE_THREADS
+  // If HAVE_THREADS is defined, the Mutex class implements an actual
+  // mutex object of some kind.  If HAVE_THREADS is not defined, this
+  // will be a MutexDummyImpl, which does nothing much anyway, so we
+  // might as well not even store a pointer to one--but MutexDummyImpl
+  // does perform some circularity testing in the case that NDEBUG is
+  // not defined, so we go ahead and store a pointer in that case too.
+#if defined(HAVE_THREADS) || !defined(NDEBUG)
   const Mutex *_mutex;
 #endif
 };