summaryrefslogtreecommitdiffstats
path: root/src/rccmutex.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2010-07-16 09:58:26 +0200
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2010-07-16 09:58:26 +0200
commit4ed874500c66aeb60cb11a0acc081dbc113eec51 (patch)
tree425587d32b7a7e005c37c9c2c941936c0c65c0d6 /src/rccmutex.c
parent0f6f7b770b84bd02d8c94c84ed9da78bc11ba8ca (diff)
downloadlibrcc-4ed874500c66aeb60cb11a0acc081dbc113eec51.tar.gz
librcc-4ed874500c66aeb60cb11a0acc081dbc113eec51.tar.bz2
librcc-4ed874500c66aeb60cb11a0acc081dbc113eec51.tar.xz
librcc-4ed874500c66aeb60cb11a0acc081dbc113eec51.zip
Windows fixes and CMake scripts to build under Windows
Diffstat (limited to 'src/rccmutex.c')
-rw-r--r--src/rccmutex.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/rccmutex.c b/src/rccmutex.c
index dce817a..5df962a 100644
--- a/src/rccmutex.c
+++ b/src/rccmutex.c
@@ -20,8 +20,17 @@
#include <stdlib.h>
#include <time.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+
+#ifdef WIN32
+# include <windows.h>
+#endif /* WIN32 */
+
#include "rccmutex.h"
+
#define RCC_MUTEX_SLEEP 500
rcc_mutex rccMutexCreate() {
@@ -49,7 +58,9 @@ void rccMutexFree(rcc_mutex mutex) {
int rccMutexLock(rcc_mutex mutex) {
#ifndef HAVE_PTHREAD
+# ifdef HAVE_NANOSLEEP
struct timespec ts;
+# endif /* HAVE_NANOSLEEP */
#endif /* !HAVE_PTHREAD */
if (!mutex) return -1;
@@ -58,9 +69,15 @@ int rccMutexLock(rcc_mutex mutex) {
return pthread_mutex_lock(&mutex->mutex);
#else
while (mutex->mutex) {
+# if defined(HAVE_NANOSLEEP)
ts.tv_sec = RCC_MUTEX_SLEEP / 1000000;
ts.tv_nsec = (RCC_MUTEX_SLEEP % 1000000)*1000;
nanosleep(&ts, NULL);
+# elif defined (HAVE_USLEEP)
+ usleep(RCC_MUTEX_SLEEP);
+# elif defined (WIN32)
+ Sleep((RCC_MUTEX_SLEEP<1000)?1:RCC_MUTEX_SLEEP/1000);
+# endif /* HAVE_NANOSLEEP */
}
mutex->mutex = 1;