Changes GC.cs
[mono-project.git] / mono / utils / mono-coop-semaphore.h
blobf717fd50b24914a199e9086992b8856049b9d703
1 /**
2 * \file
3 */
5 #ifndef __MONO_COOP_SEMAPHORE_H__
6 #define __MONO_COOP_SEMAPHORE_H__
8 #include <config.h>
9 #include <glib.h>
11 #include "mono-os-semaphore.h"
12 #include "mono-threads-api.h"
14 /* We put the OS sync primitives in struct, so the compiler will warn us if
15 * we use mono_os_(mutex|cond|sem)_... on MonoCoop(Mutex|Cond|Sem) structures */
17 typedef struct _MonoCoopSem MonoCoopSem;
18 struct _MonoCoopSem {
19 MonoSemType s;
22 static inline void
23 mono_coop_sem_init (MonoCoopSem *sem, int value)
25 mono_os_sem_init (&sem->s, value);
28 static inline void
29 mono_coop_sem_destroy (MonoCoopSem *sem)
31 mono_os_sem_destroy (&sem->s);
34 static inline gint
35 mono_coop_sem_wait (MonoCoopSem *sem, MonoSemFlags flags)
37 gint res;
39 MONO_ENTER_GC_SAFE;
41 res = mono_os_sem_wait (&sem->s, flags);
43 MONO_EXIT_GC_SAFE;
45 return res;
48 static inline MonoSemTimedwaitRet
49 mono_coop_sem_timedwait (MonoCoopSem *sem, guint timeout_ms, MonoSemFlags flags)
51 MonoSemTimedwaitRet res;
53 MONO_ENTER_GC_SAFE;
55 res = mono_os_sem_timedwait (&sem->s, timeout_ms, flags);
57 MONO_EXIT_GC_SAFE;
59 return res;
62 static inline void
63 mono_coop_sem_post (MonoCoopSem *sem)
65 mono_os_sem_post (&sem->s);
68 #endif /* __MONO_COOP_SEMAPHORE_H__ */