Merge pull request #3040 from xmcclure/debugger-step-recursive
[mono.git] / mono / utils / mono-coop-semaphore.h
1
2 #ifndef __MONO_COOP_SEMAPHORE_H__
3 #define __MONO_COOP_SEMAPHORE_H__
4
5 #include <config.h>
6 #include <glib.h>
7
8 #include "mono-os-semaphore.h"
9 #include "mono-threads-api.h"
10
11 G_BEGIN_DECLS
12
13 /* We put the OS sync primitives in struct, so the compiler will warn us if
14  * we use mono_os_(mutex|cond|sem)_... on MonoCoop(Mutex|Cond|Sem) structures */
15
16 typedef struct _MonoCoopSem MonoCoopSem;
17 struct _MonoCoopSem {
18         MonoSemType s;
19 };
20
21 static inline gint
22 mono_coop_sem_init (MonoCoopSem *sem, int value)
23 {
24         return mono_os_sem_init (&sem->s, value);
25 }
26
27 static inline gint
28 mono_coop_sem_destroy (MonoCoopSem *sem)
29 {
30         return mono_os_sem_destroy (&sem->s);
31 }
32
33 static inline gint
34 mono_coop_sem_wait (MonoCoopSem *sem, MonoSemFlags flags)
35 {
36         gint res;
37
38         MONO_ENTER_GC_SAFE;
39
40         res = mono_os_sem_wait (&sem->s, flags);
41
42         MONO_EXIT_GC_SAFE;
43
44         return res;
45 }
46
47 static inline gint
48 mono_coop_sem_timedwait (MonoCoopSem *sem, guint timeout_ms, MonoSemFlags flags)
49 {
50         gint res;
51
52         MONO_ENTER_GC_SAFE;
53
54         res = mono_os_sem_timedwait (&sem->s, timeout_ms, flags);
55
56         MONO_EXIT_GC_SAFE;
57
58         return res;
59 }
60
61 static inline gint
62 mono_coop_sem_post (MonoCoopSem *sem)
63 {
64         return mono_os_sem_post (&sem->s);
65 }
66
67 G_END_DECLS
68
69 #endif /* __MONO_COOP_SEMAPHORE_H__ */