aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-04-16 06:59:44 -0700
committerChris Robinson <[email protected]>2014-04-16 06:59:44 -0700
commitb020dd13fda12ffa275f6c8165dcad481f9658d6 (patch)
tree8d9ab0e331765c305f62ab4cf609261913333b64
parent184cf30cf70d0efcba8cfb7c27f464dbc4a3edaf (diff)
Avoid using a Sleep() wrapper
-rw-r--r--Alc/backends/null.c6
-rw-r--r--Alc/backends/oss.c4
-rw-r--r--Alc/backends/pulseaudio.c2
-rw-r--r--Alc/backends/solaris.c2
-rw-r--r--Alc/backends/wave.c6
-rw-r--r--Alc/compat.h1
-rw-r--r--Alc/helpers.c10
-rw-r--r--Alc/threads.c2
-rw-r--r--OpenAL32/Include/threads.h12
9 files changed, 24 insertions, 21 deletions
diff --git a/Alc/backends/null.c b/Alc/backends/null.c
index 4a3aa2d2..26e63b2e 100644
--- a/Alc/backends/null.c
+++ b/Alc/backends/null.c
@@ -94,9 +94,9 @@ static int ALCnullBackend_mixerProc(void *ptr)
}
if(avail-done < device->UpdateSize)
{
- ALuint restTime = (ALuint)((device->UpdateSize - (avail-done)) * 1000 /
- device->Frequency);
- Sleep(restTime);
+ long restTime = (long)((device->UpdateSize - (avail-done)) * 1000000000 /
+ device->Frequency);
+ al_nssleep(0, restTime);
continue;
}
diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c
index bf54bb4c..2a4e4dd3 100644
--- a/Alc/backends/oss.c
+++ b/Alc/backends/oss.c
@@ -131,7 +131,7 @@ static int ALCplaybackOSS_mixerProc(void *ptr)
break;
}
- Sleep(1);
+ al_nssleep(0, 1000000);
continue;
}
@@ -362,7 +362,7 @@ static int ALCcaptureOSS_recordProc(void *ptr)
}
if(amt == 0)
{
- Sleep(1);
+ al_nssleep(0, 1000000);
continue;
}
if(self->doCapture)
diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c
index 6b7b00a3..8bc147a8 100644
--- a/Alc/backends/pulseaudio.c
+++ b/Alc/backends/pulseaudio.c
@@ -783,7 +783,7 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
if(o) pa_operation_unref(o);
}
pa_threaded_mainloop_unlock(self->loop);
- Sleep(1);
+ al_nssleep(0, 1000000);
pa_threaded_mainloop_lock(self->loop);
continue;
}
diff --git a/Alc/backends/solaris.c b/Alc/backends/solaris.c
index 0498ef30..7a8c23d2 100644
--- a/Alc/backends/solaris.c
+++ b/Alc/backends/solaris.c
@@ -86,7 +86,7 @@ static int SolarisProc(void *ptr)
break;
}
- Sleep(1);
+ al_nssleep(0, 1000000);
continue;
}
diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c
index 3d15cab1..5f5c92c1 100644
--- a/Alc/backends/wave.c
+++ b/Alc/backends/wave.c
@@ -93,8 +93,8 @@ static int WaveProc(void *ptr)
ALuint now, start;
ALuint64 avail, done;
size_t fs;
- const ALuint restTime = (ALuint64)Device->UpdateSize * 1000 /
- Device->Frequency / 2;
+ const long restTime = (long)((ALuint64)Device->UpdateSize * 1000000000 /
+ Device->Frequency / 2);
SetThreadName(MIXER_THREAD_NAME);
@@ -116,7 +116,7 @@ static int WaveProc(void *ptr)
}
if(avail-done < Device->UpdateSize)
{
- Sleep(restTime);
+ al_nssleep(0, restTime);
continue;
}
diff --git a/Alc/compat.h b/Alc/compat.h
index d5e0c7e9..7d577cb7 100644
--- a/Alc/compat.h
+++ b/Alc/compat.h
@@ -30,7 +30,6 @@ FILE *al_fopen(const char *fname, const char *mode);
#include <pthread.h>
ALuint timeGetTime(void);
-void Sleep(ALuint t);
#define althread_key_t pthread_key_t
#define althread_key_create pthread_key_create
diff --git a/Alc/helpers.c b/Alc/helpers.c
index 062ec83c..17fc9c2c 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -451,16 +451,6 @@ 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)
diff --git a/Alc/threads.c b/Alc/threads.c
index 10109630..2dd85414 100644
--- a/Alc/threads.c
+++ b/Alc/threads.c
@@ -37,6 +37,8 @@ extern inline int almtx_lock(almtx_t *mtx);
extern inline int almtx_unlock(almtx_t *mtx);
extern inline int almtx_trylock(almtx_t *mtx);
+extern inline void al_nssleep(time_t sec, long nsec);
+
#define THREAD_STACK_SIZE (1*1024*1024) /* 1MB */
diff --git a/OpenAL32/Include/threads.h b/OpenAL32/Include/threads.h
index 84082604..b6a29f65 100644
--- a/OpenAL32/Include/threads.h
+++ b/OpenAL32/Include/threads.h
@@ -2,6 +2,7 @@
#define AL_THREADS_H
#include <time.h>
+#include <errno.h>
enum {
@@ -163,4 +164,15 @@ int almtx_timedlock(almtx_t *mtx, const struct timespec *ts);
void SetThreadName(const char *name);
+
+inline void al_nssleep(time_t sec, long nsec)
+{
+ struct timespec ts, rem;
+ ts.tv_sec = sec;
+ ts.tv_nsec = nsec;
+
+ while(althrd_sleep(&ts, &rem) == -1 && errno == EINTR)
+ ts = rem;
+}
+
#endif /* AL_THREADS_H */