Avoid using a Sleep() wrapper

This commit is contained in:
Chris Robinson 2014-04-16 06:59:44 -07:00
parent 184cf30cf7
commit b020dd13fd
9 changed files with 24 additions and 21 deletions

View File

@ -94,9 +94,9 @@ static int ALCnullBackend_mixerProc(void *ptr)
}
if(avail-done < device->UpdateSize)
{
ALuint restTime = (ALuint)((device->UpdateSize - (avail-done)) * 1000 /
long restTime = (long)((device->UpdateSize - (avail-done)) * 1000000000 /
device->Frequency);
Sleep(restTime);
al_nssleep(0, restTime);
continue;
}

View File

@ -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)

View File

@ -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;
}

View File

@ -86,7 +86,7 @@ static int SolarisProc(void *ptr)
break;
}
Sleep(1);
al_nssleep(0, 1000000);
continue;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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)

View File

@ -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 */

View File

@ -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 */