4 * Copyright 1998 Alexandre Julliard
12 #include "server/request.h"
16 /***********************************************************************
17 * CreateEvent32A (KERNEL32.156)
19 HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
20 BOOL initial_state, LPCSTR name )
22 struct create_event_request req;
23 struct create_event_reply reply;
24 int len = name ? strlen(name) + 1 : 0;
26 req.manual_reset = manual_reset;
27 req.initial_state = initial_state;
28 req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
29 CLIENT_SendRequest( REQ_CREATE_EVENT, -1, 2, &req, sizeof(req), name, len );
31 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
32 if (reply.handle == -1) return 0;
37 /***********************************************************************
38 * CreateEvent32W (KERNEL32.157)
40 HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
41 BOOL initial_state, LPCWSTR name )
43 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
44 HANDLE ret = CreateEventA( sa, manual_reset, initial_state, nameA );
45 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
49 /***********************************************************************
50 * WIN16_CreateEvent (KERNEL.457)
52 HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state )
54 return CreateEventA( NULL, manual_reset, initial_state, NULL );
58 /***********************************************************************
59 * OpenEvent32A (KERNEL32.536)
61 HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
63 struct open_event_request req;
64 struct open_event_reply reply;
65 int len = name ? strlen(name) + 1 : 0;
68 req.inherit = inherit;
69 CLIENT_SendRequest( REQ_OPEN_EVENT, -1, 2, &req, sizeof(req), name, len );
70 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
71 if (reply.handle == -1) return 0; /* must return 0 on failure, not -1 */
72 return (HANDLE)reply.handle;
76 /***********************************************************************
77 * OpenEvent32W (KERNEL32.537)
79 HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
81 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
82 HANDLE ret = OpenEventA( access, inherit, nameA );
83 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
88 /***********************************************************************
91 * Execute an event operation (set,reset,pulse).
93 static BOOL EVENT_Operation( HANDLE handle, enum event_op op )
95 struct event_op_request req;
99 CLIENT_SendRequest( REQ_EVENT_OP, -1, 1, &req, sizeof(req) );
100 return !CLIENT_WaitReply( NULL, NULL, 0 );
104 /***********************************************************************
105 * PulseEvent (KERNEL32.557)
107 BOOL WINAPI PulseEvent( HANDLE handle )
109 return EVENT_Operation( handle, PULSE_EVENT );
113 /***********************************************************************
114 * SetEvent (KERNEL32.644)
116 BOOL WINAPI SetEvent( HANDLE handle )
118 return EVENT_Operation( handle, SET_EVENT );
122 /***********************************************************************
123 * ResetEvent (KERNEL32.586)
125 BOOL WINAPI ResetEvent( HANDLE handle )
127 return EVENT_Operation( handle, RESET_EVENT );
131 /***********************************************************************
132 * NOTE: The Win95 VWin32_Event routines given below are really low-level
133 * routines implemented directly by VWin32. The user-mode libraries
134 * implement Win32 synchronisation routines on top of these low-level
135 * primitives. We do it the other way around here :-)
138 /***********************************************************************
139 * VWin32_EventCreate (KERNEL.442)
141 HANDLE WINAPI VWin32_EventCreate(VOID)
143 HANDLE hEvent = CreateEventA( NULL, FALSE, 0, NULL );
144 return ConvertToGlobalHandle( hEvent );
147 /***********************************************************************
148 * VWin32_EventDestroy (KERNEL.443)
150 VOID WINAPI VWin32_EventDestroy(HANDLE event)
152 CloseHandle( event );
155 /***********************************************************************
156 * VWin32_EventWait (KERNEL.450)
158 VOID WINAPI VWin32_EventWait(HANDLE event)
160 SYSLEVEL_ReleaseWin16Lock();
161 WaitForSingleObject( event, INFINITE );
162 SYSLEVEL_RestoreWin16Lock();
165 /***********************************************************************
166 * VWin32_EventSet (KERNEL.451)
168 VOID WINAPI VWin32_EventSet(HANDLE event)