Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
TestAutoLock.cpp File Reference
#include "nsAutoLock.h"
#include "prthread.h"

Go to the source code of this file.

Functions

static void PR_CALLBACK run (void *arg)
int main (int argc, char **argv)
 The Xalan testcases app.

Variables

PRLockgLock
int gCount

Function Documentation

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 61 of file TestAutoLock.cpp.

{
    gLock = PR_NewLock();
    gCount = 0;

    // This shouldn't compile
    //nsAutoLock* l1 = new nsAutoLock(theLock);
    //delete l1;

    // Create a block-scoped lock. This should compile.
    {
        nsAutoLock l2(gLock);
    }

    // Fork a thread to access the shared variable in a tight loop
    PRThread* t1 =
        PR_CreateThread(PR_SYSTEM_THREAD,
                        run,
                        nsnull,
                        PR_PRIORITY_NORMAL,
                        PR_GLOBAL_THREAD,
                        PR_JOINABLE_THREAD,
                        0);

    // ...and now do the same thing ourselves
    run(nsnull);

    // Wait for the background thread to finish, if necessary.
    PR_JoinThread(t1);
    return 0;
}

Here is the call graph for this function:

static void PR_CALLBACK run ( void arg) [static]

Definition at line 50 of file TestAutoLock.cpp.

{
    for (int i = 0; i < 1000000; ++i) {
        nsAutoLock guard(gLock);
        ++gCount;
        PR_ASSERT(gCount == 1);
        --gCount;
    }
}

Variable Documentation

Definition at line 48 of file TestAutoLock.cpp.

Definition at line 47 of file TestAutoLock.cpp.