Drop ioctl
[apc.git] / winhog.c
blob3daad4ee2d073e0d261b170c318987df309dbcea
1 #define WIN32_LEAN_AND_MEAN
2 #include <windows.h>
3 #include <mmsystem.h>
4 #include <stdio.h>
5 #include <stdlib.h>
7 #define NITERS 10
8 static volatile stop;
10 static DWORD_PTR hog (DWORD_PTR count)
12 DWORD_PTR i = 0;
13 while (i < count && !stop) ++i;
14 return i;
17 static void CALLBACK timer_callback (
18 UINT uTimerID,
19 UINT uMsg,
20 DWORD_PTR dwUser,
21 DWORD_PTR dw1,
22 DWORD_PTR dw2
25 if (!dwUser)
26 stop = 1;
27 else {
28 stop = 0;
29 hog (dwUser);
33 static UINT settimer (DWORD_PTR val)
35 MMRESULT mr;
37 mr = timeSetEvent (1, 0, timer_callback, val,
38 TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
39 if (!mr) {
40 fprintf (stderr, "timeSetEvent failed: %ld\n", GetLastError ());
41 exit (EXIT_FAILURE);
43 return mr;
46 int main (int argc, char **argv)
48 int i, mini, maxi;
49 UINT id;
50 MMRESULT mr;
51 DWORD prevmask, wr;
52 DWORD_PTR est[NITERS];
53 double d;
54 DWORD_PTR mask;
56 if (argc > 1)
57 mask = atoi (argv[1]);
58 else
59 mask = 1;
61 prevmask = SetProcessAffinityMask (GetCurrentProcess (), mask);
62 if (!prevmask) {
63 fprintf (stderr, "SetProcessAffinityMask failed: %ld\n", GetLastError ());
64 exit (EXIT_FAILURE);
66 id = settimer (0);
68 for (i = 0; i < NITERS; ++i) {
69 stop = 0;
70 est[i] = hog ((DWORD_PTR) 0 - 1);
73 mr = timeKillEvent (id);
74 if (mr != TIMERR_NOERROR) {
75 fprintf (stderr, "timeKillEvent failed: %ld\n", GetLastError ());
76 exit (EXIT_FAILURE);
79 mini = 0;
80 maxi = 0;
82 for (i = 0; i < NITERS; ++i) {
83 if (est[i] < est[mini]) mini = i;
84 if (est[i] > est[maxi]) maxi = i;
87 d = 0.0;
88 for (i = 0; i < NITERS; ++i) {
89 fprintf (stderr, "%f\n", (double) est[i]);
90 if (i == mini || i == maxi) continue;
91 d += est[i];
93 d = d / (NITERS - 2);
94 d = d - d / 10;
95 fprintf (stderr, "%f\n", d);
97 settimer (d);
99 Sleep (INFINITE);
100 return 0;