diff options
author | Chris Robinson <[email protected]> | 2011-09-20 14:36:42 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-09-20 14:43:53 -0700 |
commit | e01092a0da3559a8c8c28312388ef9b416319aae (patch) | |
tree | f1409665bd4b968dff91baec7c7dabcf1109c2b4 /Alc/helpers.c | |
parent | 312e9a436da35fcb66839e0873d67c2e8f0aa3b7 (diff) |
Move Sleep implementation into helper.c and emulate sched_yield for Windows
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r-- | Alc/helpers.c | 14 |
1 files changed, 12 insertions, 2 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) |