bug 491462: fix some typos and compiler warnings in deadlock detector. r=bsmedberg
authorChris Jones <jones.chris.g@gmail.com>
Thu, 14 May 2009 13:07:30 -0700
changeset 28345 ba18c5ef04d583b1ee3bfbf621614cd07bc3f228
parent 28344 1e0a18bbe498eecd540ecfdfbaab9adfc06cb4cb
child 28346 7d1b9ef54d27863b0d537328d5a9acfa2681da1a
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs491462
milestone1.9.2a1pre
bug 491462: fix some typos and compiler warnings in deadlock detector. r=bsmedberg
xpcom/glue/CondVar.h
xpcom/tests/TestDeadlockDetector.cpp
xpcom/tests/TestDeadlockDetectorScalability.cpp
--- a/xpcom/glue/CondVar.h
+++ b/xpcom/glue/CondVar.h
@@ -55,17 +55,17 @@ namespace mozilla {
 class NS_COM_GLUE CondVar : BlockingResourceBase
 {
 public:
     /**
      * CondVar
      *
      * The CALLER owns |lock|.
      *
-     * @param aLock An Mutex to associate with this condition variable.
+     * @param aLock A Mutex to associate with this condition variable.
      * @param aName A name which can reference this monitor
      * @returns If failure, nsnull.
      *          If success, a valid Monitor* which must be destroyed
      *          by Monitor::DestroyMonitor()
      **/
     CondVar(Mutex& aLock, const char* aName) :
         BlockingResourceBase(aName, eCondVar),
         mLock(&aLock)
--- a/xpcom/tests/TestDeadlockDetector.cpp
+++ b/xpcom/tests/TestDeadlockDetector.cpp
@@ -37,22 +37,24 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "prenv.h"
 #include "prerror.h"
 #include "prio.h"
 #include "prproces.h"
 
-#include "TestHarness.h"
+#include "nsMemory.h"
 
 #include "mozilla/CondVar.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/Mutex.h"
 
+#include "TestHarness.h"
+
 using namespace mozilla;
 
 static PRThread*
 spawn(void (*run)(void*), void* arg)
 {
     return PR_CreateThread(PR_SYSTEM_THREAD,
                            run,
                            arg,
@@ -70,18 +72,16 @@ spawn(void (*run)(void*), void* arg)
 
 
 #define FAIL(why)                               \
     do {                                        \
         fail(why);                              \
         return NS_ERROR_FAILURE;                \
     } while (0);
 
-#define ALEN(arr) (sizeof(arr) / sizeof(arr[0]))
-
 //-----------------------------------------------------------------------------
 
 static const char* sPathToThisBinary;
 static const char* sAssertBehaviorEnv = "XPCOM_DEBUG_BREAK=abort";
 
 class Subprocess
 {
 public:
@@ -480,41 +480,41 @@ mozilla::Mutex* cndMs[4];
 const PRUint32 K = 100000;
 
 static void
 ContentionNoDeadlock_thread(void* arg)
 {
     PRInt32 starti = NS_PTR_TO_INT32(arg);
 
     for (PRUint32 k = 0; k < K; ++k) {
-        for (PRInt32 i = starti; i < ALEN(cndMs); ++i)
+        for (PRInt32 i = starti; i < (PRInt32) NS_ARRAY_LENGTH(cndMs); ++i)
             cndMs[i]->Lock();
         // comment out the next two lines for deadlocking fun!
-        for (PRInt32 i = ALEN(cndMs) - 1; i >= starti; --i)
+        for (PRInt32 i = NS_ARRAY_LENGTH(cndMs) - 1; i >= starti; --i)
             cndMs[i]->Unlock();
 
         starti = (starti + 1) % 3;
     }
 }
 
 nsresult
 ContentionNoDeadlock_Child()
 {
     PRThread* threads[3];
 
-    for (PRUint32 i = 0; i < ALEN(cndMs); ++i)
+    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(cndMs); ++i)
         cndMs[i] = new mozilla::Mutex("dd.cnd.ms");
 
-    for (PRInt32 i = 0; i < ALEN(threads); ++i)
+    for (PRInt32 i = 0; i < (PRInt32) NS_ARRAY_LENGTH(threads); ++i)
         threads[i] = spawn(ContentionNoDeadlock_thread, NS_INT32_TO_PTR(i));
 
-    for (PRUint32 i = 0; i < ALEN(threads); ++i)
+    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(threads); ++i)
         PR_JoinThread(threads[i]);
 
-    for (PRUint32 i = 0; i < ALEN(cndMs); ++i)
+    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(cndMs); ++i)
         delete cndMs[i];
 
     return 0;
 }
 
 nsresult
 ContentionNoDeadlock()
 {
--- a/xpcom/tests/TestDeadlockDetectorScalability.cpp
+++ b/xpcom/tests/TestDeadlockDetectorScalability.cpp
@@ -63,18 +63,25 @@
 #else
 #  include "mozilla/Mutex.h"
    typedef mozilla::Mutex* lock_t;
 #  define NEWLOCK(n) new mozilla::Mutex(n)
 #  define DELETELOCK(v) delete (v)
 #  define AUTOLOCK(v, l) mozilla::MutexAutoLock v(*l)
 #endif
 
+// def/undef these to run particular tests.
+#undef DD_TEST1
+#undef DD_TEST2
+#undef DD_TEST3
+
 //-----------------------------------------------------------------------------
 
+#ifdef DD_TEST1
+
 static void
 AllocLockRecurseUnlockFree(int i)
 {
     if (0 == i)
         return;
 
     lock_t lock = NEWLOCK("deadlockDetector.scalability.t1");
     {
@@ -88,18 +95,22 @@ AllocLockRecurseUnlockFree(int i)
 // frees all the resources in the chain.
 static nsresult
 LengthNDepChain(int N)
 {
     AllocLockRecurseUnlockFree(N);
     PASS();
 }
 
+#endif
+
 //-----------------------------------------------------------------------------
 
+#ifdef DD_TEST2
+
 // This test creates a single lock that is ordered < N resources, then
 // repeatedly exercises this order k times.
 static nsresult
 OneLockNDeps(const int N, const int K)
 {
     lock_t lock = NEWLOCK("deadlockDetector.scalability.t2.master");
     lock_t* locks = new lock_t[N];
     if (!locks)
@@ -124,19 +135,22 @@ OneLockNDeps(const int N, const int K)
 
     for (int i = 0; i < N; ++i)
         DELETELOCK(locks[i]);
     delete[] locks;
 
     PASS();
 }
 
+#endif
 
 //-----------------------------------------------------------------------------
 
+#ifdef DD_TEST3
+
 // This test creates N resources and adds the theoretical maximum number
 // of dependencies, O(N^2).  It then repeats that sequence of
 // acquisitions k times.  Finally, all resources are freed.
 //
 // It's very difficult to perform well on this test.  It's put forth as a
 // challenge problem.
 
 static nsresult
@@ -165,38 +179,40 @@ MaxDepsNsq(const int N, const int K)
 
     for (int i = 0; i < N; ++i)
         DELETELOCK(locks[i]);
     delete[] locks;
 
     PASS();
 }
 
+#endif
+
 //-----------------------------------------------------------------------------
 
 int
 main(int argc, char** argv)
 {
     ScopedXPCOM xpcom("Deadlock detector scalability");
     if (xpcom.failed())
         return 1;
 
     int rv = 0;
 
     // Uncomment these tests to run them.  Not expected to be common.
 
-#if 0
+#ifdef DD_TEST1
     if (NS_FAILED(LengthNDepChain(1 << 14))) // 16K
         rv = 1;
 #endif
 
-#if 0
+#ifdef DD_TEST2
     if (NS_FAILED(OneLockNDeps(1 << 14, 100))) // 16k
         rv = 1;
 #endif
 
-#if 0
+#ifdef DD_TEST3
     if (NS_FAILED(MaxDepsNsq(1 << 10, 10))) // 1k
         rv = 1;
 #endif
 
     return rv;
 }