diff options
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/backends/alsa.c | 30 | ||||
-rw-r--r-- | Alc/backends/dsound.c | 14 | ||||
-rw-r--r-- | Alc/backends/null.c | 18 | ||||
-rw-r--r-- | Alc/backends/oss.c | 31 | ||||
-rw-r--r-- | Alc/backends/qsa.c | 50 | ||||
-rw-r--r-- | Alc/backends/sndio.c | 14 | ||||
-rw-r--r-- | Alc/backends/solaris.c | 14 | ||||
-rw-r--r-- | Alc/backends/wave.c | 15 | ||||
-rw-r--r-- | Alc/threads.c | 118 |
9 files changed, 93 insertions, 211 deletions
diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index 106e788e..56cbb9ca 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -390,12 +390,12 @@ typedef struct ALCplaybackAlsa { ALsizei size; volatile int killNow; - althread_t thread; + althrd_t thread; } ALCplaybackAlsa; DECLARE_ALCBACKEND_VTABLE(ALCplaybackAlsa); -static ALuint ALCplaybackAlsa_mixerProc(ALvoid *ptr); -static ALuint ALCplaybackAlsa_mixerNoMMapProc(ALvoid *ptr); +static int ALCplaybackAlsa_mixerProc(void *ptr); +static int ALCplaybackAlsa_mixerNoMMapProc(void *ptr); static void ALCplaybackAlsa_Construct(ALCplaybackAlsa *self, ALCdevice *device); static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, void, Destruct) @@ -418,7 +418,7 @@ static void ALCplaybackAlsa_Construct(ALCplaybackAlsa *self, ALCdevice *device) } -static ALuint ALCplaybackAlsa_mixerProc(ALvoid *ptr) +static int ALCplaybackAlsa_mixerProc(void *ptr) { ALCplaybackAlsa *self = (ALCplaybackAlsa*)ptr; ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; @@ -510,7 +510,7 @@ static ALuint ALCplaybackAlsa_mixerProc(ALvoid *ptr) return 0; } -static ALuint ALCplaybackAlsa_mixerNoMMapProc(ALvoid *ptr) +static int ALCplaybackAlsa_mixerNoMMapProc(void *ptr) { ALCplaybackAlsa *self = (ALCplaybackAlsa*)ptr; ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; @@ -810,7 +810,7 @@ error: static ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; - ALuint (*thread_func)(ALvoid*) = NULL; + int (*thread_func)(void*) = NULL; snd_pcm_hw_params_t *hp = NULL; snd_pcm_access_t access; const char *funcerr; @@ -846,7 +846,8 @@ static ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self) } thread_func = ALCplaybackAlsa_mixerProc; } - if(!StartThread(&self->thread, thread_func, self)) + self->killNow = 0; + if(althrd_create(&self->thread, thread_func, self) != althrd_success) { ERR("Could not create playback thread\n"); free(self->buffer); @@ -864,13 +865,14 @@ error: static void ALCplaybackAlsa_stop(ALCplaybackAlsa *self) { - if(self->thread) - { - self->killNow = 1; - StopThread(self->thread); - self->thread = NULL; - } - self->killNow = 0; + int res; + + if(self->killNow) + return; + + self->killNow = 1; + althrd_join(self->thread, &res); + free(self->buffer); self->buffer = NULL; } diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index f6846791..ac97e54d 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -77,7 +77,7 @@ typedef struct { HANDLE NotifyEvent; volatile int killNow; - althread_t thread; + althrd_t thread; } DSoundPlaybackData; typedef struct { @@ -180,7 +180,7 @@ static BOOL CALLBACK DSoundEnumDevices(LPGUID guid, LPCWSTR desc, LPCWSTR UNUSED } -FORCE_ALIGN static ALuint DSoundPlaybackProc(ALvoid *ptr) +FORCE_ALIGN static int DSoundPlaybackProc(void *ptr) { ALCdevice *Device = (ALCdevice*)ptr; DSoundPlaybackData *data = (DSoundPlaybackData*)Device->ExtraData; @@ -596,7 +596,8 @@ static ALCboolean DSoundStartPlayback(ALCdevice *device) { DSoundPlaybackData *data = (DSoundPlaybackData*)device->ExtraData; - if(!StartThread(&data->thread, DSoundPlaybackProc, device)) + data->killNow = 0; + if(althrd_create(&data->thread, DSoundPlaybackProc, device) != althrd_success) return ALC_FALSE; return ALC_TRUE; @@ -605,15 +606,14 @@ static ALCboolean DSoundStartPlayback(ALCdevice *device) static void DSoundStopPlayback(ALCdevice *device) { DSoundPlaybackData *data = device->ExtraData; + int res; - if(!data->thread) + if(data->killNow) return; data->killNow = 1; - StopThread(data->thread); - data->thread = NULL; + althrd_join(data->thread, &res); - data->killNow = 0; IDirectSoundBuffer_Stop(data->Buffer); } diff --git a/Alc/backends/null.c b/Alc/backends/null.c index 6b59ef7a..4a3aa2d2 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -37,11 +37,11 @@ typedef struct ALCnullBackend { DERIVE_FROM_TYPE(ALCbackend); volatile int killNow; - althread_t thread; + althrd_t thread; } ALCnullBackend; DECLARE_ALCBACKEND_VTABLE(ALCnullBackend); -static ALuint ALCnullBackend_mixerProc(ALvoid *ptr); +static int ALCnullBackend_mixerProc(void *ptr); static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device); static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, Destruct) @@ -68,7 +68,7 @@ static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device) } -static ALuint ALCnullBackend_mixerProc(ALvoid *ptr) +static int ALCnullBackend_mixerProc(void *ptr) { ALCnullBackend *self = (ALCnullBackend*)ptr; ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; @@ -137,21 +137,21 @@ static ALCboolean ALCnullBackend_reset(ALCnullBackend *self) static ALCboolean ALCnullBackend_start(ALCnullBackend *self) { - if(!StartThread(&self->thread, ALCnullBackend_mixerProc, self)) + self->killNow = 0; + if(althrd_create(&self->thread, ALCnullBackend_mixerProc, self) != althrd_success) return ALC_FALSE; return ALC_TRUE; } static void ALCnullBackend_stop(ALCnullBackend *self) { - if(!self->thread) + int res; + + if(self->killNow) return; self->killNow = 1; - StopThread(self->thread); - self->thread = NULL; - - self->killNow = 0; + althrd_join(self->thread, &res); } DEFINE_ALCBACKEND_VTABLE(ALCnullBackend); diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c index f0532cdf..bf54bb4c 100644 --- a/Alc/backends/oss.c +++ b/Alc/backends/oss.c @@ -78,10 +78,10 @@ typedef struct ALCplaybackOSS { int data_size; volatile int killNow; - althread_t thread; + althrd_t thread; } ALCplaybackOSS; -static ALuint ALCplaybackOSS_mixerProc(ALvoid *ptr); +static int ALCplaybackOSS_mixerProc(void *ptr); static void ALCplaybackOSS_Construct(ALCplaybackOSS *self, ALCdevice *device); static DECLARE_FORWARD(ALCplaybackOSS, ALCbackend, void, Destruct) @@ -99,7 +99,7 @@ DECLARE_DEFAULT_ALLOCATORS(ALCplaybackOSS) DEFINE_ALCBACKEND_VTABLE(ALCplaybackOSS); -static ALuint ALCplaybackOSS_mixerProc(ALvoid *ptr) +static int ALCplaybackOSS_mixerProc(void *ptr) { ALCplaybackOSS *self = (ALCplaybackOSS*)ptr; ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; @@ -275,7 +275,8 @@ static ALCboolean ALCplaybackOSS_start(ALCplaybackOSS *self) self->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType); self->mix_data = calloc(1, self->data_size); - if(!StartThread(&self->thread, ALCplaybackOSS_mixerProc, self)) + self->killNow = 0; + if(althrd_create(&self->thread, ALCplaybackOSS_mixerProc, self) != althrd_success) { free(self->mix_data); self->mix_data = NULL; @@ -287,14 +288,14 @@ static ALCboolean ALCplaybackOSS_start(ALCplaybackOSS *self) static void ALCplaybackOSS_stop(ALCplaybackOSS *self) { - if(!self->thread) + int res; + + if(self->killNow) return; self->killNow = 1; - StopThread(self->thread); - self->thread = NULL; + althrd_join(self->thread, &res); - self->killNow = 0; if(ioctl(self->fd, SNDCTL_DSP_RESET) != 0) ERR("Error resetting device: %s\n", strerror(errno)); @@ -315,10 +316,10 @@ typedef struct ALCcaptureOSS { int doCapture; volatile int killNow; - althread_t thread; + althrd_t thread; } ALCcaptureOSS; -static ALuint ALCcaptureOSS_recordProc(ALvoid *ptr); +static int ALCcaptureOSS_recordProc(void *ptr); static void ALCcaptureOSS_Construct(ALCcaptureOSS *self, ALCdevice *device); static DECLARE_FORWARD(ALCcaptureOSS, ALCbackend, void, Destruct) @@ -336,7 +337,7 @@ DECLARE_DEFAULT_ALLOCATORS(ALCcaptureOSS) DEFINE_ALCBACKEND_VTABLE(ALCcaptureOSS); -static ALuint ALCcaptureOSS_recordProc(ALvoid *ptr) +static int ALCcaptureOSS_recordProc(void *ptr) { ALCcaptureOSS *self = (ALCcaptureOSS*)ptr; ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; @@ -483,7 +484,8 @@ static ALCenum ALCcaptureOSS_open(ALCcaptureOSS *self, const ALCchar *name) self->data_size = info.fragsize; self->read_data = calloc(1, self->data_size); - if(!StartThread(&self->thread, ALCcaptureOSS_recordProc, self)) + self->killNow = 0; + if(althrd_create(&self->thread, ALCcaptureOSS_recordProc, self) != althrd_success) { device->ExtraData = NULL; close(self->fd); @@ -498,9 +500,10 @@ static ALCenum ALCcaptureOSS_open(ALCcaptureOSS *self, const ALCchar *name) static void ALCcaptureOSS_close(ALCcaptureOSS *self) { + int res; + self->killNow = 1; - StopThread(self->thread); - self->killNow = 0; + althrd_join(self->thread, &res); close(self->fd); self->fd = -1; diff --git a/Alc/backends/qsa.c b/Alc/backends/qsa.c index d9d7c87b..b77a66ad 100644 --- a/Alc/backends/qsa.c +++ b/Alc/backends/qsa.c @@ -34,8 +34,7 @@ #include "threads.h" -typedef struct -{ +typedef struct { snd_pcm_t* pcmHandle; int audio_fd; @@ -46,27 +45,24 @@ typedef struct ALsizei size; volatile int killNow; - althread_t thread; + althrd_t thread; } qsa_data; -typedef struct -{ +typedef struct { ALCchar* name; int card; int dev; } DevMap; -static const ALCchar qsaDevice[]="QSA Default"; +static const ALCchar qsaDevice[] = "QSA Default"; static DevMap* allDevNameMap; static ALuint numDevNames; static DevMap* allCaptureDevNameMap; static ALuint numCaptureDevNames; -static const struct -{ +static const struct { int32_t format; -} formatlist[]= -{ +} formatlist[] = { {SND_PCM_SFMT_FLOAT_LE}, {SND_PCM_SFMT_S32_LE}, {SND_PCM_SFMT_U32_LE}, @@ -77,11 +73,9 @@ static const struct {0}, }; -static const struct -{ +static const struct { int32_t rate; -} ratelist[]= -{ +} ratelist[] = { {192000}, {176400}, {96000}, @@ -98,11 +92,9 @@ static const struct {0}, }; -static const struct -{ +static const struct { int32_t channels; -} channellist[]= -{ +} channellist[] = { {8}, {7}, {6}, @@ -112,7 +104,7 @@ static const struct {0}, }; -static DevMap* deviceList(int type, ALuint* count) +static DevMap *deviceList(int type, ALuint *count) { snd_ctl_t* handle; snd_pcm_info_t pcminfo; @@ -178,7 +170,7 @@ static DevMap* deviceList(int type, ALuint* count) } -FORCE_ALIGN static ALuint qsa_proc_playback(ALvoid* ptr) +FORCE_ALIGN static int qsa_proc_playback(void* ptr) { ALCdevice* device=(ALCdevice*)ptr; qsa_data* data=(qsa_data*)device->ExtraData; @@ -616,7 +608,8 @@ static ALCboolean qsa_start_playback(ALCdevice* device) { qsa_data *data = (qsa_data*)device->ExtraData; - if(!StartThread(&data->thread, qsa_proc_playback, device)) + data->killNow = 0; + if(althrd_create(&data->thread, qsa_proc_playback, device) != althrd_success) return ALC_FALSE; return ALC_TRUE; @@ -624,15 +617,14 @@ static ALCboolean qsa_start_playback(ALCdevice* device) static void qsa_stop_playback(ALCdevice* device) { - qsa_data* data=(qsa_data*)device->ExtraData; + qsa_data *data = (qsa_data*)device->ExtraData; + int res; - if (data->thread) - { - data->killNow=1; - StopThread(data->thread); - data->thread=NULL; - } - data->killNow=0; + if(data->killNow) + return; + + data->killNow = 1; + althrd_join(data->thread, &res); } /***********/ diff --git a/Alc/backends/sndio.c b/Alc/backends/sndio.c index 9e43f08a..cdc052c8 100644 --- a/Alc/backends/sndio.c +++ b/Alc/backends/sndio.c @@ -47,11 +47,11 @@ typedef struct { ALsizei data_size; volatile int killNow; - althread_t thread; + althrd_t thread; } sndio_data; -static ALuint sndio_proc(ALvoid *ptr) +static int sndio_proc(void *ptr) { ALCdevice *device = ptr; sndio_data *data = device->ExtraData; @@ -224,7 +224,8 @@ static ALCboolean sndio_start_playback(ALCdevice *device) data->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType); data->mix_data = calloc(1, data->data_size); - if(!StartThread(&data->thread, sndio_proc, device)) + data->killNow = 0; + if(althrd_create(&data->thread, sndio_proc, device) != althrd_success) { sio_stop(data->sndHandle); free(data->mix_data); @@ -238,15 +239,14 @@ static ALCboolean sndio_start_playback(ALCdevice *device) static void sndio_stop_playback(ALCdevice *device) { sndio_data *data = device->ExtraData; + int res; - if(!data->thread) + if(data->killNow) return; data->killNow = 1; - StopThread(data->thread); - data->thread = NULL; + althrd_join(data->thread, &res); - data->killNow = 0; if(!sio_stop(data->sndHandle)) ERR("Error stopping device\n"); diff --git a/Alc/backends/solaris.c b/Alc/backends/solaris.c index edd0e060..0498ef30 100644 --- a/Alc/backends/solaris.c +++ b/Alc/backends/solaris.c @@ -50,11 +50,11 @@ typedef struct { int data_size; volatile int killNow; - althread_t thread; + althrd_t thread; } solaris_data; -static ALuint SolarisProc(ALvoid *ptr) +static int SolarisProc(void *ptr) { ALCdevice *Device = (ALCdevice*)ptr; solaris_data *data = (solaris_data*)Device->ExtraData; @@ -211,7 +211,8 @@ static ALCboolean solaris_start_playback(ALCdevice *device) data->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType); data->mix_data = calloc(1, data->data_size); - if(!StartThread(&data->thread, SolarisProc, device)) + data->killNow = 0; + if(althrd_create(&data->thread, SolarisProc, device) != althrd_success) { free(data->mix_data); data->mix_data = NULL; @@ -224,15 +225,14 @@ static ALCboolean solaris_start_playback(ALCdevice *device) static void solaris_stop_playback(ALCdevice *device) { solaris_data *data = (solaris_data*)device->ExtraData; + int res; - if(!data->thread) + if(data->killNow) return; data->killNow = 1; - StopThread(data->thread); - data->thread = NULL; + althrd_join(data->thread, &res); - data->killNow = 0; if(ioctl(data->fd, AUDIO_DRAIN) < 0) ERR("Error draining device: %s\n", strerror(errno)); diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c index f6bedc08..3d15cab1 100644 --- a/Alc/backends/wave.c +++ b/Alc/backends/wave.c @@ -42,7 +42,7 @@ typedef struct { ALuint size; volatile int killNow; - althread_t thread; + althrd_t thread; } wave_data; @@ -85,7 +85,7 @@ static void fwrite32le(ALuint val, FILE *f) } -static ALuint WaveProc(ALvoid *ptr) +static int WaveProc(void *ptr) { ALCdevice *Device = (ALCdevice*)ptr; wave_data *data = (wave_data*)Device->ExtraData; @@ -291,7 +291,8 @@ static ALCboolean wave_start_playback(ALCdevice *device) return ALC_FALSE; } - if(!StartThread(&data->thread, WaveProc, device)) + data->killNow = 0; + if(althrd_create(&data->thread, WaveProc, device) != althrd_success) { free(data->buffer); data->buffer = NULL; @@ -306,15 +307,13 @@ static void wave_stop_playback(ALCdevice *device) wave_data *data = (wave_data*)device->ExtraData; ALuint dataLen; long size; + int res; - if(!data->thread) + if(data->killNow) return; data->killNow = 1; - StopThread(data->thread); - data->thread = NULL; - - data->killNow = 0; + althrd_join(data->thread, &res); free(data->buffer); data->buffer = NULL; diff --git a/Alc/threads.c b/Alc/threads.c index d910716c..10109630 100644 --- a/Alc/threads.c +++ b/Alc/threads.c @@ -46,59 +46,6 @@ extern inline int almtx_trylock(almtx_t *mtx); #include <windows.h> #include <mmsystem.h> -typedef struct althread_info { - ALuint (*func)(ALvoid*); - ALvoid *ptr; - HANDLE hdl; -} althread_info; - -static DWORD CALLBACK StarterFunc(void *ptr) -{ - althread_info *inf = (althread_info*)ptr; - ALuint ret; - - ret = inf->func(inf->ptr); - ExitThread((DWORD)ret); - - return (DWORD)ret; -} - - -ALboolean StartThread(althread_t *thread, ALuint (*func)(ALvoid*), ALvoid *ptr) -{ - althread_info *info; - DWORD dummy; - - info = malloc(sizeof(*info)); - if(!info) return AL_FALSE; - - info->func = func; - info->ptr = ptr; - - info->hdl = CreateThread(NULL, THREAD_STACK_SIZE, StarterFunc, info, 0, &dummy); - if(!info->hdl) - { - free(info); - return AL_FALSE; - } - - *thread = info; - return AL_TRUE; -} - -ALuint StopThread(althread_t thread) -{ - DWORD ret = 0; - - WaitForSingleObject(thread->hdl, INFINITE); - GetExitCodeThread(thread->hdl, &ret); - CloseHandle(thread->hdl); - - free(thread); - - return (ALuint)ret; -} - void SetThreadName(const char *name) { @@ -243,66 +190,9 @@ int almtx_timedlock(almtx_t *mtx, const struct timespec *ts) #include <pthread_np.h> #endif -typedef struct althread_info { - ALuint (*func)(ALvoid*); - ALvoid *ptr; - ALuint ret; - pthread_t hdl; -} althread_info; - -static void *StarterFunc(void *ptr) -{ - althread_info *inf = (althread_info*)ptr; - inf->ret = inf->func(inf->ptr); - return NULL; -} - -ALboolean StartThread(althread_t *thread, ALuint (*func)(ALvoid*), ALvoid *ptr) -{ - pthread_attr_t attr; - althread_info *info; - - info = malloc(sizeof(*info)); - if(!info) return AL_FALSE; - - if(pthread_attr_init(&attr) != 0) - { - free(info); - return AL_FALSE; - } - if(pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE) != 0) - { - pthread_attr_destroy(&attr); - free(info); - return AL_FALSE; - } - - info->func = func; - info->ptr = ptr; - if(pthread_create(&info->hdl, &attr, StarterFunc, info) != 0) - { - pthread_attr_destroy(&attr); - free(info); - return AL_FALSE; - } - pthread_attr_destroy(&attr); - - *thread = info; - return AL_TRUE; -} - -ALuint StopThread(althread_t thread) -{ - ALuint ret; - - pthread_join(thread->hdl, NULL); - ret = thread->ret; - - free(thread); - - return ret; -} +extern inline althrd_t althrd_current(void); +extern inline int althrd_sleep(const struct timespec *ts, struct timespec *rem); void SetThreadName(const char *name) @@ -322,10 +212,6 @@ void SetThreadName(const char *name) } -extern inline althrd_t althrd_current(void); -extern inline int althrd_sleep(const struct timespec *ts, struct timespec *rem); - - typedef struct thread_cntr { althrd_start_t func; void *arg; |