[threads] Make OSEvent alertable to fix bug #51653 (#4347)
[mono.git] / mono / utils / os-event.h
1
2 #ifndef _MONO_UTILS_OS_EVENT_H_
3 #define _MONO_UTILS_OS_EVENT_H_
4
5 #include <config.h>
6 #include <glib.h>
7
8 #include "mono-os-mutex.h"
9
10 #ifndef MONO_INFINITE_WAIT
11 #define MONO_INFINITE_WAIT ((guint32) 0xFFFFFFFF)
12 #endif
13
14 #define MONO_OS_EVENT_WAIT_MAXIMUM_OBJECTS 64
15
16 typedef enum {
17         MONO_OS_EVENT_WAIT_RET_SUCCESS_0 =  0,
18         MONO_OS_EVENT_WAIT_RET_ALERTED   = -1,
19         MONO_OS_EVENT_WAIT_RET_TIMEOUT   = -2,
20 } MonoOSEventWaitRet;
21
22 typedef struct _MonoOSEvent MonoOSEvent;
23
24 typedef void (*MonoOSEventFreeCb) (MonoOSEvent*);
25
26 struct _MonoOSEvent {
27 #ifdef HOST_WIN32
28         gpointer handle;
29 #else
30         GPtrArray *conds;
31         gboolean signalled;
32 #endif
33 };
34
35 void
36 mono_os_event_init (MonoOSEvent *event, gboolean initial);
37
38 void
39 mono_os_event_destroy (MonoOSEvent *event);
40
41 void
42 mono_os_event_set (MonoOSEvent *event);
43
44 void
45 mono_os_event_reset (MonoOSEvent *event);
46
47 MonoOSEventWaitRet
48 mono_os_event_wait_one (MonoOSEvent *event, guint32 timeout, gboolean alertable);
49
50 MonoOSEventWaitRet
51 mono_os_event_wait_multiple (MonoOSEvent **events, gsize nevents, gboolean waitall, guint32 timeout, gboolean alertable);
52
53 #endif /* _MONO_UTILS_OS_EVENT_H_ */