-
Notifications
You must be signed in to change notification settings - Fork 2
/
event_win.c
50 lines (44 loc) · 1.06 KB
/
event_win.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <windows.h>
typedef struct event_s {
HANDLE handle;
} event_s;
bool event_wait(void *ctx, int32_t timeout_ms) {
event_s *event = (event_s *)ctx;
if (!event)
return false;
if (WaitForSingleObject(event->handle, timeout_ms ? timeout_ms : INFINITE) != WAIT_OBJECT_0)
return false;
return true;
}
bool event_set(void *ctx) {
event_s *event = (event_s *)ctx;
if (!event || !SetEvent(event->handle))
return false;
return true;
}
void *event_create(void) {
event_s *event = (event_s *)calloc(1, sizeof(event_s));
if (!event)
return NULL;
event->handle = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!event->handle) {
free(event);
return NULL;
}
return event;
}
bool event_delete(void **ctx) {
if (!ctx)
return false;
event_s *event = (event_s *)*ctx;
if (!event)
return false;
CloseHandle(event->handle);
free(event);
*ctx = NULL;
return true;
}