From 335acc495f7ee02a6ebce1ad288c8ab1763d6816 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 14 May 2009 13:07:30 -0700 Subject: [PATCH] bug 491462: fix some typos and compiler warnings in deadlock detector. r=bsmedberg --- xpcom/glue/CondVar.h | 2 +- xpcom/tests/TestDeadlockDetector.cpp | 18 +++++++-------- .../tests/TestDeadlockDetectorScalability.cpp | 22 ++++++++++++++++--- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/xpcom/glue/CondVar.h b/xpcom/glue/CondVar.h index 50119c6ee06..e186f889d9f 100644 --- a/xpcom/glue/CondVar.h +++ b/xpcom/glue/CondVar.h @@ -60,7 +60,7 @@ public: * * 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 diff --git a/xpcom/tests/TestDeadlockDetector.cpp b/xpcom/tests/TestDeadlockDetector.cpp index f44b9bd852e..bee3703109e 100644 --- a/xpcom/tests/TestDeadlockDetector.cpp +++ b/xpcom/tests/TestDeadlockDetector.cpp @@ -42,12 +42,14 @@ #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* @@ -75,8 +77,6 @@ spawn(void (*run)(void*), void* arg) return NS_ERROR_FAILURE; \ } while (0); -#define ALEN(arr) (sizeof(arr) / sizeof(arr[0])) - //----------------------------------------------------------------------------- static const char* sPathToThisBinary; @@ -485,10 +485,10 @@ 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; @@ -500,16 +500,16 @@ 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; diff --git a/xpcom/tests/TestDeadlockDetectorScalability.cpp b/xpcom/tests/TestDeadlockDetectorScalability.cpp index 3e738b67c9c..c6e3433ba23 100644 --- a/xpcom/tests/TestDeadlockDetectorScalability.cpp +++ b/xpcom/tests/TestDeadlockDetectorScalability.cpp @@ -68,8 +68,15 @@ # 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) { @@ -93,8 +100,12 @@ LengthNDepChain(int 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 @@ -129,9 +140,12 @@ OneLockNDeps(const int N, const int K) 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. @@ -170,6 +184,8 @@ MaxDepsNsq(const int N, const int K) PASS(); } +#endif + //----------------------------------------------------------------------------- int @@ -183,17 +199,17 @@ main(int argc, char** argv) // 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