b41be412e9496c4c045e93480b781830c428bd22
[reactos.git] / reactos / ntoskrnl / io / event.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/event.c
6 * PURPOSE: Implements named events
7 * PROGRAMMER: David Welch (welch@mcmail.com)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ntoskrnl.h>
15 #include <internal/debug.h>
16
17 /* FUNCTIONS *****************************************************************/
18
19 /*
20 * @implemented
21 */
22 PKEVENT STDCALL
23 IoCreateNotificationEvent(PUNICODE_STRING EventName,
24 PHANDLE EventHandle)
25 {
26 OBJECT_ATTRIBUTES ObjectAttributes;
27 PKEVENT Event;
28 HANDLE Handle;
29 NTSTATUS Status;
30
31 InitializeObjectAttributes(&ObjectAttributes,
32 EventName,
33 OBJ_OPENIF,
34 NULL,
35 NULL);
36
37 Status = ZwCreateEvent(&Handle,
38 EVENT_ALL_ACCESS,
39 &ObjectAttributes,
40 NotificationEvent,
41 TRUE);
42 if (!NT_SUCCESS(Status))
43 {
44 return NULL;
45 }
46
47 ObReferenceObjectByHandle(Handle,
48 0,
49 ExEventObjectType,
50 KernelMode,
51 (PVOID*)&Event,
52 NULL);
53 ObDereferenceObject(Event);
54
55 *EventHandle = Handle;
56
57 return Event;
58 }
59
60 /*
61 * @implemented
62 */
63 PKEVENT STDCALL
64 IoCreateSynchronizationEvent(PUNICODE_STRING EventName,
65 PHANDLE EventHandle)
66 {
67 OBJECT_ATTRIBUTES ObjectAttributes;
68 KPROCESSOR_MODE PreviousMode;
69 PKEVENT Event;
70 HANDLE Handle;
71 NTSTATUS Status;
72
73 PreviousMode = ExGetPreviousMode();
74
75 InitializeObjectAttributes(&ObjectAttributes,
76 EventName,
77 OBJ_OPENIF,
78 NULL,
79 NULL);
80
81 Status = ZwCreateEvent(&Handle,
82 EVENT_ALL_ACCESS,
83 &ObjectAttributes,
84 SynchronizationEvent,
85 TRUE);
86
87 if (!NT_SUCCESS(Status))
88 {
89 return NULL;
90 }
91
92 ObReferenceObjectByHandle(Handle,
93 0,
94 ExEventObjectType,
95 KernelMode,
96 (PVOID*)&Event,
97 NULL);
98 ObDereferenceObject(Event);
99
100 *EventHandle = Handle;
101
102 return Event;
103 }
104
105 /* EOF */