update for HEAD-2003091401
[reactos.git] / apps / tests / eventpair / eventpair.c
1 /*
2  * Author: Skywing (skywing@valhallalegends.com)
3  * Date: 09/09/2003
4  * Purpose: Test Thread-EventPair functionality.
5  */
6
7 #include <windows.h>
8 #include <stdio.h>
9 #include <ddk/ntddk.h>
10
11 #ifndef NTAPI
12 #define NTAPI WINAPI
13 #endif
14
15 HANDLE MakeEventPair()
16 {
17         NTSTATUS Status;
18         HANDLE EventPair;
19         OBJECT_ATTRIBUTES Attributes;
20
21         InitializeObjectAttributes(&Attributes, NULL, 0, NULL, NULL);
22         Status = NtCreateEventPair(&EventPair, STANDARD_RIGHTS_ALL, &Attributes);
23         printf("Status %08x creating eventpair\n", Status);
24         return EventPair;
25 }
26
27 DWORD __stdcall threadfunc(void* eventpair)
28 {
29         printf("Thread: Set eventpair status %08x\n", NtSetInformationThread(NtCurrentThread(), ThreadEventPair, &eventpair, sizeof(HANDLE)));
30         Sleep(2500);
31
32         printf("Thread: Setting low and waiting high...\n");
33         printf("Thread: status = %08x\n", NtSetLowWaitHighThread());
34         printf("Thread: status = %08x\n", NtSetHighWaitLowThread());
35         printf("Thread: Terminating...\n");
36         return 0;
37 }
38
39 int main(int ac, char **av)
40 {
41         DWORD id;
42         HANDLE EventPair, Thread;
43
44         printf("Main: NtSetLowWaitHighThread is at %08x\n", NtSetLowWaitHighThread);
45
46         EventPair = MakeEventPair();
47
48         if(!EventPair) {
49                 printf("Main: Could not create event pair.\n");
50                 return 0;
51         }
52
53         printf("Main: EventPair = %08x\n", EventPair);
54         Thread = CreateThread(0, 0, threadfunc, EventPair, 0, &id);
55         printf("Main: ThreadId for new thread is %08x\n", id);
56         printf("Main: Setting high and waiting low\n");
57         printf("Main: status = %08x\n", NtSetHighWaitLowEventPair(EventPair));
58         Sleep(2500);
59         printf("Main: status = %08x\n", NtSetLowWaitHighEventPair(EventPair));
60         NtClose(EventPair);
61         /* WaitForSingleObject(Thread, INFINITE); FIXME: Waiting on thread handle causes double spinlock acquisition (and subsequent crash) in PsUnblockThread -  ntoskrnl/ps/thread.c */
62         NtClose(Thread);
63         printf("Main: Terminating...\n");
64         return 0;
65 }