2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* Copyright (C) 1994 Cazamar Systems, Inc. */
12 #include <afs/param.h>
22 static osi_mutex_t main_perfMutex;
30 #define main_NITERS 20000 /* bops between the two */
32 long main_Perf1(long parm)
35 lock_ObtainMutex(&main_perfMutex);
36 if (!(flags & STARTA)) {
37 /* we're not supposed to be running */
38 osi_SleepM((long) &flags, &main_perfMutex);
42 /* hand off to the other guy */
45 osi_Wakeup((long) &flags);
47 /* we're running, bump the counter.
48 * do this after hand-off, so the other guy gets to run.
51 if (count > main_NITERS) {
55 osi_SleepM((long) &flags, &main_perfMutex);
58 lock_ReleaseMutex(&main_perfMutex);
59 osi_Wakeup((long) &done); /* wakeup anyone waiting for completion */
63 long main_Perf2(long parm)
66 lock_ObtainMutex(&main_perfMutex);
67 if (!(flags & STARTB)) {
68 /* we're not supposed to be running */
69 osi_SleepM((long) &flags, &main_perfMutex);
73 /* hand off to the other guy */
76 osi_Wakeup((long) &flags);
78 /* we're running, bump the counter. Do after hand-off so other
79 * guy also gets to notice that we're done.
82 if (count > main_NITERS) {
86 osi_SleepM((long)&flags, &main_perfMutex);
89 lock_ReleaseMutex(&main_perfMutex);
90 osi_Wakeup((long) &done); /* wakeup anyone waiting for completion */
94 main_PerfTest(HANDLE hWnd)
103 main_ForceDisplay(hWnd);
105 /* create three processes, two modifiers and one scanner. The scanner
106 * checks that the basic invariants are being maintained, while the
107 * modifiers modify the global variables, maintaining certain invariants
110 * The invariant is that global variables a and b total 100.
116 lock_InitializeMutex(&main_perfMutex, "perf test mutex");
118 mod1Handle = CreateThread((SECURITY_ATTRIBUTES *) 0, 0,
119 (LPTHREAD_START_ROUTINE) main_Perf1, 0, 0, &mod1ID);
120 if (mod1Handle == NULL) return -1;
122 mod2Handle = CreateThread((SECURITY_ATTRIBUTES *) 0, 0,
123 (LPTHREAD_START_ROUTINE) main_Perf2, 0, 0, &mod2ID);
124 if (mod2Handle == NULL) return -2;
126 /* start running check daemon */
128 /* copy out count of # of dudes finished */
129 lock_ObtainMutex(&main_perfMutex);
131 lock_ReleaseMutex(&main_perfMutex);
134 osi_SleepM((long) &done, &main_perfMutex);
137 /* done, release and finalize all locks */
138 lock_FinalizeMutex(&main_perfMutex);
140 /* finally clean up thread handles */
141 CloseHandle(mod1Handle);
142 CloseHandle(mod2Handle);