summaryrefslogtreecommitdiff
path: root/nsprpub/pr/tests/lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/tests/lock.c')
-rw-r--r--nsprpub/pr/tests/lock.c173
1 files changed, 101 insertions, 72 deletions
diff --git a/nsprpub/pr/tests/lock.c b/nsprpub/pr/tests/lock.c
index 178315ae60..83a4f41801 100644
--- a/nsprpub/pr/tests/lock.c
+++ b/nsprpub/pr/tests/lock.c
@@ -9,12 +9,12 @@
**
** Modification History:
** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
-** The debug mode will print all of the printfs associated with this test.
-** The regress mode will be the default mode. Since the regress tool limits
+** The debug mode will print all of the printfs associated with this test.
+** The regress mode will be the default mode. Since the regress tool limits
** the output to a one line status:PASS or FAIL,all of the printf statements
-** have been handled with an if (debug_mode) statement.
+** have been handled with an if (debug_mode) statement.
** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
-** recognize the return code from tha main program.
+** recognize the return code from tha main program.
**
** 11-Aug-97 LarryH. Win16 port of NSPR.
** - Added "PASS", "FAIL" messages on completion.
@@ -25,7 +25,7 @@
** - l <num> to control the number of loops
** - c <num> to control the number of CPUs.
** (was positional argv).
-**
+**
**
***********************************************************************/
@@ -149,8 +149,8 @@ static PRIntervalTime ContentiousLock(PRUint32 loops)
contention->ml = PR_NewLock();
contention->interval = contention_interval;
thread = PR_CreateThread(
- PR_USER_THREAD, LockContender, contention,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, LockContender, contention,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
@@ -211,12 +211,18 @@ static PRIntervalTime NonContentiousMonitor(PRUint32 loops)
static void PR_CALLBACK TryEntry(void *arg)
{
PRMonitor *ml = (PRMonitor*)arg;
- if (debug_mode) PR_fprintf(std_err, "Reentrant thread created\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Reentrant thread created\n");
+ }
PR_EnterMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
- if (debug_mode) PR_fprintf(std_err, "Reentrant thread acquired monitor\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Reentrant thread acquired monitor\n");
+ }
PR_ExitMonitor(ml);
- if (debug_mode) PR_fprintf(std_err, "Reentrant thread released monitor\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Reentrant thread released monitor\n");
+ }
} /* TryEntry */
static PRIntervalTime ReentrantMonitor(PRUint32 loops)
@@ -224,32 +230,40 @@ static PRIntervalTime ReentrantMonitor(PRUint32 loops)
PRStatus status;
PRThread *thread;
PRMonitor *ml = PR_NewMonitor();
- if (debug_mode) PR_fprintf(std_err, "\nMonitor created for reentrant test\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "\nMonitor created for reentrant test\n");
+ }
PR_EnterMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
PR_EnterMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
- if (debug_mode) PR_fprintf(std_err, "Monitor acquired twice\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Monitor acquired twice\n");
+ }
thread = PR_CreateThread(
- PR_USER_THREAD, TryEntry, ml,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, TryEntry, ml,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
PR_Sleep(PR_SecondsToInterval(1));
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
PR_ExitMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
- if (debug_mode) PR_fprintf(std_err, "Monitor released first time\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Monitor released first time\n");
+ }
PR_ExitMonitor(ml);
- if (debug_mode) PR_fprintf(std_err, "Monitor released second time\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Monitor released second time\n");
+ }
status = PR_JoinThread(thread);
- if (debug_mode) PR_fprintf(std_err,
- "Reentrant thread joined %s\n",
- (status == PR_SUCCESS) ? "successfully" : "in error");
+ if (debug_mode) PR_fprintf(std_err,
+ "Reentrant thread joined %s\n",
+ (status == PR_SUCCESS) ? "successfully" : "in error");
PR_DestroyMonitor(ml);
return 0;
@@ -283,8 +297,8 @@ static PRUint32 ContentiousMonitor(PRUint32 loops)
contention->ml = PR_NewMonitor();
contention->interval = contention_interval;
thread = PR_CreateThread(
- PR_USER_THREAD, MonitorContender, contention,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, MonitorContender, contention,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
@@ -352,8 +366,8 @@ static PRIntervalTime ContentiousCMonitor(PRUint32 loops)
contention->loops = loops;
contention->interval = contention_interval;
thread = PR_CreateThread(
- PR_USER_THREAD, Contender, contention,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Contender, contention,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
@@ -382,17 +396,17 @@ static PRIntervalTime ContentiousCMonitor(PRUint32 loops)
static PRIntervalTime Test(
const char* msg, PRUint32 (*test)(PRUint32 loops),
PRUint32 loops, PRIntervalTime overhead)
-{
+{
/*
* overhead - overhead not measured by the test.
* duration - wall clock time it took to perform test.
- * predicted - extra time test says should not be counted
+ * predicted - extra time test says should not be counted
*
* Time accountable to the test is duration - overhead - predicted
* All times are Intervals and accumulated for all iterations.
*/
PRFloat64 elapsed;
- PRIntervalTime accountable, duration;
+ PRIntervalTime accountable, duration;
PRUintn spaces = PL_strlen(msg);
PRIntervalTime timeout, timein = PR_IntervalNow();
PRIntervalTime predicted = test(loops);
@@ -405,11 +419,15 @@ static PRIntervalTime Test(
accountable -= overhead;
elapsed = (PRFloat64)PR_IntervalToMicroseconds(accountable);
PR_fprintf(PR_STDOUT, "%s:", msg);
- while (spaces++ < 50) PR_fprintf(PR_STDOUT, " ");
- if ((PRInt32)accountable < 0)
+ while (spaces++ < 50) {
+ PR_fprintf(PR_STDOUT, " ");
+ }
+ if ((PRInt32)accountable < 0) {
PR_fprintf(PR_STDOUT, "*****.** usecs/iteration\n");
- else
+ }
+ else {
PR_fprintf(PR_STDOUT, "%8.2f usecs/iteration\n", elapsed/loops);
+ }
}
return duration;
} /* Test */
@@ -420,62 +438,72 @@ int main(int argc, char **argv)
PRIntervalTime duration;
PRUint32 cpu, cpus = 2, loops = 100;
-
+
PR_STDIO_INIT();
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
Command line argument -l <num> sets the number of loops.
Command line argument -c <num> sets the number of cpus.
Usage: lock [-d] [-l <num>] [-c <num>]
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dvl:c:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dvl:c:");
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'd': /* debug mode */
- debug_mode = PR_TRUE;
- break;
- case 'v': /* debug mode */
- verbosity = PR_TRUE;
- break;
- case 'l': /* number of loops */
- loops = atoi(opt->value);
- break;
- case 'c': /* number of cpus */
- cpus = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'v': /* debug mode */
+ verbosity = PR_TRUE;
+ break;
+ case 'l': /* number of loops */
+ loops = atoi(opt->value);
+ break;
+ case 'c': /* number of cpus */
+ cpus = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
- /* main test */
+ /* main test */
PR_SetConcurrency(8);
- if (loops == 0) loops = 100;
+ if (loops == 0) {
+ loops = 100;
+ }
if (debug_mode)
{
std_err = PR_STDERR;
PR_fprintf(std_err, "Lock: Using %d loops\n", loops);
}
- if (cpus == 0) cpus = 2;
- if (debug_mode) PR_fprintf(std_err, "Lock: Using %d cpu(s)\n", cpus);
+ if (cpus == 0) {
+ cpus = 2;
+ }
+ if (debug_mode) {
+ PR_fprintf(std_err, "Lock: Using %d cpu(s)\n", cpus);
+ }
(void)Sleeper(10); /* try filling in the caches */
for (cpu = 1; cpu <= cpus; ++cpu)
{
- if (debug_mode) PR_fprintf(std_err, "\nLock: Using %d CPU(s)\n", cpu);
+ if (debug_mode) {
+ PR_fprintf(std_err, "\nLock: Using %d CPU(s)\n", cpu);
+ }
PR_SetConcurrency(cpu);
duration = Test("Overhead of PR_Sleep", Sleeper, loops, 0);
@@ -498,20 +526,21 @@ int main(int argc, char **argv)
PR_fprintf(
std_err, "%s: test %s\n", "Lock(mutex) test",
((rv) ? "passed" : "failed"));
- else {
- if (!rv)
- failed_already=1;
- }
-
- if(failed_already)
- {
- PR_fprintf(PR_STDOUT, "FAIL\n");
- return 1;
- }
- else
+ else {
+ if (!rv) {
+ failed_already=1;
+ }
+ }
+
+ if(failed_already)
+ {
+ PR_fprintf(PR_STDOUT, "FAIL\n");
+ return 1;
+ }
+ else
{
- PR_fprintf(PR_STDOUT, "PASS\n");
- return 0;
+ PR_fprintf(PR_STDOUT, "PASS\n");
+ return 0;
}
} /* main */