Merge pull request #1273 from joelmartinez/docs-unified-fix
[mono.git] / mono / utils / mono-semaphore.h
index b90237f03c57483ca2714609dc92987ae8953674..17dce622dfafecd33b64760f25d632e4963749ab 100644 (file)
 
 #include <config.h>
 #include <glib.h>
-#ifdef HAVE_SEMAPHORE_H
+#include <time.h>
+#if defined(HAVE_SEMAPHORE_H) && !defined(HOST_WIN32)
 #include <semaphore.h>
 #endif
 #include <mono/io-layer/io-layer.h>
+#include <mono/utils/mono-publib.h>
 
-#if defined (HAVE_SEMAPHORE_H) || defined (USE_MACH_SEMA)
+#if (defined (HAVE_SEMAPHORE_H) || defined (USE_MACH_SEMA)) && !defined(HOST_WIN32)
 #  define MONO_HAS_SEMAPHORES
 
 #  if defined (USE_MACH_SEMA)
@@ -32,7 +34,7 @@ typedef sem_t MonoSemType;
 #    define MONO_SEM_INIT(addr,value) sem_init ((addr), 0, (value))
 #    define MONO_SEM_DESTROY(sem) sem_destroy ((sem))
 #  endif
-#elif defined(TARGET_WIN32) || defined(_WAPI_SEMAPHORES_H)
+#else
 #  define MONO_HAS_SEMAPHORES
 typedef HANDLE MonoSemType;
 #    define MONO_SEM_INIT(addr,initial) do {*(addr) = CreateSemaphore ( NULL,(initial),0x7FFFFFFF,NULL);} while(0)
@@ -45,11 +47,17 @@ typedef HANDLE MonoSemType;
 #define MONO_SEM_TIMEDWAIT(sem, timeout_ms) MONO_SEM_TIMEDWAIT_ALERTABLE(sem, timeout_ms, FALSE)
 #define MONO_SEM_TIMEDWAIT_ALERTABLE(sem, timeout_ms, alertable) mono_sem_timedwait ((sem), (timeout_ms), alertable) 
 
+#define MONO_SEM_WAIT_UNITERRUPTIBLE(sem) do { \
+       while (MONO_SEM_WAIT ((sem)) != 0) {    \
+               /*if (EINTR != errno) ABORT("sem_wait failed"); */      \
+       }       \
+} while (0)
+
 G_BEGIN_DECLS
 
-int mono_sem_wait (MonoSemType *sem, gboolean alertable);
-int mono_sem_timedwait (MonoSemType *sem, guint32 timeout_ms, gboolean alertable);
-int mono_sem_post (MonoSemType *sem);
+MONO_API int mono_sem_wait (MonoSemType *sem, gboolean alertable);
+MONO_API int mono_sem_timedwait (MonoSemType *sem, guint32 timeout_ms, gboolean alertable);
+MONO_API int mono_sem_post (MonoSemType *sem);
 
 G_END_DECLS
 #endif /* _MONO_SEMAPHORE_H_ */