From e01092a0da3559a8c8c28312388ef9b416319aae Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 20 Sep 2011 14:36:42 -0700 Subject: [PATCH] Move Sleep implementation into helper.c and emulate sched_yield for Windows --- Alc/helpers.c | 14 ++++++++++++-- OpenAL32/Include/alMain.h | 14 ++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Alc/helpers.c b/Alc/helpers.c index 2f598999..b4f5dcda 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -53,7 +53,7 @@ void pthread_once(pthread_once_t *once, void (*callback)(void)) { LONG ret; while((ret=InterlockedExchange(once, 1)) == 1) - Sleep(0); + sched_yield(); if(ret == 0) callback(); InterlockedExchange(once, 2); @@ -173,6 +173,16 @@ ALuint timeGetTime(void) #endif } +void Sleep(ALuint t) +{ + struct timespec tv, rem; + tv.tv_nsec = (t*1000000)%1000000000; + tv.tv_sec = t/1000; + + while(nanosleep(&tv, &rem) == -1 && errno == EINTR) + tv = rem; +} + #ifdef HAVE_DLFCN_H void *LoadLib(const char *name) @@ -255,7 +265,7 @@ void SetRTPriority(void) static void Lock(volatile ALenum *l) { while(ExchangeInt(l, AL_TRUE) == AL_TRUE) - Sleep(0); + sched_yield(); } static void Unlock(volatile ALenum *l) diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 719354f2..558f620b 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -183,6 +183,9 @@ typedef LONG pthread_once_t; #define PTHREAD_ONCE_INIT 0 void pthread_once(pthread_once_t *once, void (*callback)(void)); +static __inline int sched_yield(void) +{ SwitchToThread(); return 0; } + #else #include @@ -204,16 +207,7 @@ void EnterCriticalSection(CRITICAL_SECTION *cs); void LeaveCriticalSection(CRITICAL_SECTION *cs); ALuint timeGetTime(void); - -static __inline void Sleep(ALuint t) -{ - struct timespec tv, rem; - tv.tv_nsec = (t*1000000)%1000000000; - tv.tv_sec = t/1000; - - while(nanosleep(&tv, &rem) == -1 && errno == EINTR) - tv = rem; -} +void Sleep(ALuint t); #if defined(HAVE_DLFCN_H) #define HAVE_DYNLOAD 1 -- 2.11.4.GIT