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_named_obj_request req
;
64 struct open_named_obj_reply reply
;
65 int len
= name
? strlen(name
) + 1 : 0;
67 req
.type
= OPEN_EVENT
;
69 req
.inherit
= inherit
;
70 CLIENT_SendRequest( REQ_OPEN_NAMED_OBJ
, -1, 2, &req
, sizeof(req
), name
, len
);
71 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
72 if (reply
.handle
== -1) return 0; /* must return 0 on failure, not -1 */
73 return (HANDLE
)reply
.handle
;
77 /***********************************************************************
78 * OpenEvent32W (KERNEL32.537)
80 HANDLE WINAPI
OpenEventW( DWORD access
, BOOL inherit
, LPCWSTR name
)
82 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, name
);
83 HANDLE ret
= OpenEventA( access
, inherit
, nameA
);
84 if (nameA
) HeapFree( GetProcessHeap(), 0, nameA
);
89 /***********************************************************************
92 * Execute an event operation (set,reset,pulse).
94 static BOOL
EVENT_Operation( HANDLE handle
, enum event_op op
)
96 struct event_op_request req
;
100 CLIENT_SendRequest( REQ_EVENT_OP
, -1, 1, &req
, sizeof(req
) );
101 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
105 /***********************************************************************
106 * PulseEvent (KERNEL32.557)
108 BOOL WINAPI
PulseEvent( HANDLE handle
)
110 return EVENT_Operation( handle
, PULSE_EVENT
);
114 /***********************************************************************
115 * SetEvent (KERNEL32.644)
117 BOOL WINAPI
SetEvent( HANDLE handle
)
119 return EVENT_Operation( handle
, SET_EVENT
);
123 /***********************************************************************
124 * ResetEvent (KERNEL32.586)
126 BOOL WINAPI
ResetEvent( HANDLE handle
)
128 return EVENT_Operation( handle
, RESET_EVENT
);
132 /***********************************************************************
133 * NOTE: The Win95 VWin32_Event routines given below are really low-level
134 * routines implemented directly by VWin32. The user-mode libraries
135 * implement Win32 synchronisation routines on top of these low-level
136 * primitives. We do it the other way around here :-)
139 /***********************************************************************
140 * VWin32_EventCreate (KERNEL.442)
142 HANDLE WINAPI
VWin32_EventCreate(VOID
)
144 HANDLE hEvent
= CreateEventA( NULL
, FALSE
, 0, NULL
);
145 return ConvertToGlobalHandle( hEvent
);
148 /***********************************************************************
149 * VWin32_EventDestroy (KERNEL.443)
151 VOID WINAPI
VWin32_EventDestroy(HANDLE event
)
153 CloseHandle( event
);
156 /***********************************************************************
157 * VWin32_EventWait (KERNEL.450)
159 VOID WINAPI
VWin32_EventWait(HANDLE event
)
161 SYSLEVEL_ReleaseWin16Lock();
162 WaitForSingleObject( event
, INFINITE
);
163 SYSLEVEL_RestoreWin16Lock();
166 /***********************************************************************
167 * VWin32_EventSet (KERNEL.451)
169 VOID WINAPI
VWin32_EventSet(HANDLE event
)