bug 491462: fix some typos and compiler warnings in deadlock detector. r=bsmedberg

This commit is contained in:
Chris Jones 2009-05-14 13:07:30 -07:00
Родитель e59ec69faf
Коммит 335acc495f
3 изменённых файлов: 29 добавлений и 13 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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