Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / client_osi / perf.c
blobeade6de22a9f5c98e92d176dfe773de6ba26b78d
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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
8 */
10 /* Copyright (C) 1994 Cazamar Systems, Inc. */
12 #include <afs/param.h>
13 #include <afs/stds.h>
15 #include "windows.h"
16 #include <string.h>
17 #include "main.h"
18 #include "perf.h"
19 #include "osi.h"
20 #include <assert.h>
22 static osi_mutex_t main_perfMutex;
23 static done;
25 #define STARTA 1
26 #define STARTB 2
27 static long flags;
28 static long count;
30 #define main_NITERS 20000 /* bops between the two */
32 long main_Perf1(long parm)
34 while (1) {
35 lock_ObtainMutex(&main_perfMutex);
36 if (!(flags & STARTA)) {
37 /* we're not supposed to be running */
38 osi_SleepM((long) &flags, &main_perfMutex);
39 continue;
42 /* hand off to the other guy */
43 flags &= ~STARTA;
44 flags |= STARTB;
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.
50 count++;
51 if (count > main_NITERS) {
52 break;
55 osi_SleepM((long) &flags, &main_perfMutex);
57 done++;
58 lock_ReleaseMutex(&main_perfMutex);
59 osi_Wakeup((long) &done); /* wakeup anyone waiting for completion */
60 return 0;
63 long main_Perf2(long parm)
65 while (1) {
66 lock_ObtainMutex(&main_perfMutex);
67 if (!(flags & STARTB)) {
68 /* we're not supposed to be running */
69 osi_SleepM((long) &flags, &main_perfMutex);
70 continue;
73 /* hand off to the other guy */
74 flags &= ~STARTB;
75 flags |= STARTA;
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.
81 count++;
82 if (count > main_NITERS) {
83 break;
86 osi_SleepM((long)&flags, &main_perfMutex);
88 done++;
89 lock_ReleaseMutex(&main_perfMutex);
90 osi_Wakeup((long) &done); /* wakeup anyone waiting for completion */
91 return 0;
94 main_PerfTest(HANDLE hWnd)
96 long mod1ID;
97 long mod2ID;
98 HANDLE mod1Handle;
99 HANDLE mod2Handle;
101 osi_Init();
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
108 * by using locks.
110 * The invariant is that global variables a and b total 100.
112 done = 0;
113 count = 0;
114 flags = STARTA;
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 */
127 while (1) {
128 /* copy out count of # of dudes finished */
129 lock_ObtainMutex(&main_perfMutex);
130 if (done == 2) {
131 lock_ReleaseMutex(&main_perfMutex);
132 break;
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);
144 return 0;