2 * Copyright (C) 1998, 1989 Transarc Corporation - All rights reserved
4 * (C) COPYRIGHT IBM CORPORATION 1987, 1988
5 * LICENSED MATERIALS - PROPERTY OF IBM
9 /* Copyright (C) 1994 Cazamar Systems, Inc. */
11 #include <afs/param.h>
21 static osi_mutex_t main_perfMutex;
29 #define main_NITERS 20000 /* bops between the two */
31 long main_Perf1(long parm)
34 lock_ObtainMutex(&main_perfMutex);
35 if (!(flags & STARTA)) {
36 /* we're not supposed to be running */
37 osi_SleepM((long) &flags, &main_perfMutex);
41 /* hand off to the other guy */
44 osi_Wakeup((long) &flags);
46 /* we're running, bump the counter.
47 * do this after hand-off, so the other guy gets to run.
50 if (count > main_NITERS) {
54 osi_SleepM((long) &flags, &main_perfMutex);
57 lock_ReleaseMutex(&main_perfMutex);
58 osi_Wakeup((long) &done); /* wakeup anyone waiting for completion */
62 long main_Perf2(long parm)
65 lock_ObtainMutex(&main_perfMutex);
66 if (!(flags & STARTB)) {
67 /* we're not supposed to be running */
68 osi_SleepM((long) &flags, &main_perfMutex);
72 /* hand off to the other guy */
75 osi_Wakeup((long) &flags);
77 /* we're running, bump the counter. Do after hand-off so other
78 * guy also gets to notice that we're done.
81 if (count > main_NITERS) {
85 osi_SleepM((long)&flags, &main_perfMutex);
88 lock_ReleaseMutex(&main_perfMutex);
89 osi_Wakeup((long) &done); /* wakeup anyone waiting for completion */
93 main_PerfTest(HANDLE hWnd)
102 main_ForceDisplay(hWnd);
104 /* create three processes, two modifiers and one scanner. The scanner
105 * checks that the basic invariants are being maintained, while the
106 * modifiers modify the global variables, maintaining certain invariants
109 * The invariant is that global variables a and b total 100.
115 lock_InitializeMutex(&main_perfMutex, "perf test mutex");
117 mod1Handle = CreateThread((SECURITY_ATTRIBUTES *) 0, 0,
118 (LPTHREAD_START_ROUTINE) main_Perf1, 0, 0, &mod1ID);
119 if (mod1Handle == NULL) return -1;
121 mod2Handle = CreateThread((SECURITY_ATTRIBUTES *) 0, 0,
122 (LPTHREAD_START_ROUTINE) main_Perf2, 0, 0, &mod2ID);
123 if (mod2Handle == NULL) return -2;
125 /* start running check daemon */
127 /* copy out count of # of dudes finished */
128 lock_ObtainMutex(&main_perfMutex);
130 lock_ReleaseMutex(&main_perfMutex);
133 osi_SleepM((long) &done, &main_perfMutex);
136 /* done, release and finalize all locks */
137 lock_FinalizeMutex(&main_perfMutex);
139 /* finally clean up thread handles */
140 CloseHandle(mod1Handle);
141 CloseHandle(mod2Handle);