From c693e649e67b14d508a08a4a8cde191daa4596b0 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 19 May 2013 03:19:19 -0700 Subject: Fix a potential leak when mmdevapi fails to open --- Alc/backends/mmdevapi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Alc/backends/mmdevapi.c') diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index 2555c7f3..2181f274 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -878,6 +878,9 @@ static ALCenum MMDevApiOpenPlayback(ALCdevice *device, const ALCchar *deviceName CloseHandle(data->MsgEvent); data->MsgEvent = NULL; + free(data->devid); + data->devid = NULL; + free(data); device->ExtraData = NULL; -- cgit v1.2.3 From f93bfab82435b26fd03fe9dd0436f166758810d4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 27 Oct 2013 07:00:44 -0700 Subject: Set a name for the mixer and recording threads --- Alc/backends/alsa.c | 2 ++ Alc/backends/dsound.c | 1 + Alc/backends/mmdevapi.c | 1 + Alc/backends/null.c | 5 ++++- Alc/backends/oss.c | 2 ++ Alc/backends/pulseaudio.c | 1 + Alc/backends/qsa.c | 1 + Alc/backends/sndio.c | 1 + Alc/backends/solaris.c | 1 + Alc/backends/wave.c | 2 ++ Alc/backends/winmm.c | 2 ++ OpenAL32/Include/alMain.h | 5 +++++ 12 files changed, 23 insertions(+), 1 deletion(-) (limited to 'Alc/backends/mmdevapi.c') diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index f6c0428e..bb30dac5 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -463,6 +463,7 @@ static ALuint ALSAProc(ALvoid *ptr) int err; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); update_size = Device->UpdateSize; num_updates = Device->NumUpdates; @@ -552,6 +553,7 @@ static ALuint ALSANoMMapProc(ALvoid *ptr) int err; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); update_size = Device->UpdateSize; num_updates = Device->NumUpdates; diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index 9727dd2a..22af15d8 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -238,6 +238,7 @@ static ALuint DSoundPlaybackProc(ALvoid *ptr) HRESULT err; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); memset(&DSBCaps, 0, sizeof(DSBCaps)); DSBCaps.dwSize = sizeof(DSBCaps); diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index 2181f274..e6447bef 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -238,6 +238,7 @@ static ALuint MMDevApiProc(ALvoid *ptr) } SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); update_size = device->UpdateSize; buffer_len = update_size * device->NumUpdates; diff --git a/Alc/backends/null.c b/Alc/backends/null.c index d001cb41..73e3e8cb 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -44,6 +44,9 @@ static ALuint NullProc(ALvoid *ptr) ALuint now, start; ALuint64 avail, done; + SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); + done = 0; start = timeGetTime(); while(!data->killNow && Device->Connected) @@ -55,7 +58,7 @@ static ALuint NullProc(ALvoid *ptr) { /* Timer wrapped (50 days???). Add the remainder of the cycle to * the available count and reset the number of samples done */ - avail += ((ALuint64)1<<32)*Device->Frequency/1000 - done; + avail += (U64(1)<<32)*Device->Frequency/1000 - done; done = 0; } if(avail-done < Device->UpdateSize) diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c index 0ed49517..892e2327 100644 --- a/Alc/backends/oss.c +++ b/Alc/backends/oss.c @@ -85,6 +85,7 @@ static ALuint OSSProc(ALvoid *ptr) ssize_t wrote; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); @@ -128,6 +129,7 @@ static ALuint OSSCaptureProc(ALvoid *ptr) int amt; SetRTPriority(); + SetThreadName("alsoft-record"); frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c index f96b44fe..5b6e0fad 100644 --- a/Alc/backends/pulseaudio.c +++ b/Alc/backends/pulseaudio.c @@ -791,6 +791,7 @@ static ALuint PulseProc(ALvoid *param) ssize_t len; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); pa_threaded_mainloop_lock(data->loop); frame_size = pa_frame_size(&data->spec); diff --git a/Alc/backends/qsa.c b/Alc/backends/qsa.c index 933af5b4..2890a121 100644 --- a/Alc/backends/qsa.c +++ b/Alc/backends/qsa.c @@ -196,6 +196,7 @@ static ALuint qsa_proc_playback(ALvoid* ptr) struct timeval timeout; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); /* Increase default 10 priority to 11 to avoid jerky sound */ SchedGet(0, 0, ¶m); diff --git a/Alc/backends/sndio.c b/Alc/backends/sndio.c index 2be88746..4c3a5de6 100644 --- a/Alc/backends/sndio.c +++ b/Alc/backends/sndio.c @@ -58,6 +58,7 @@ static ALuint sndio_proc(ALvoid *ptr) size_t wrote; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType); diff --git a/Alc/backends/solaris.c b/Alc/backends/solaris.c index 1c781387..b9288197 100644 --- a/Alc/backends/solaris.c +++ b/Alc/backends/solaris.c @@ -59,6 +59,7 @@ static ALuint SolarisProc(ALvoid *ptr) int wrote; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c index 416876be..ce827fe8 100644 --- a/Alc/backends/wave.c +++ b/Alc/backends/wave.c @@ -93,6 +93,8 @@ static ALuint WaveProc(ALvoid *ptr) const ALuint restTime = (ALuint64)Device->UpdateSize * 1000 / Device->Frequency / 2; + SetThreadName(MIXER_THREAD_NAME); + frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); done = 0; diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c index 3b2b373b..e003375c 100644 --- a/Alc/backends/winmm.c +++ b/Alc/backends/winmm.c @@ -175,6 +175,7 @@ static DWORD WINAPI PlaybackThreadProc(LPVOID param) FrameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); while(GetMessage(&msg, NULL, 0, 0)) { @@ -237,6 +238,7 @@ static DWORD WINAPI CaptureThreadProc(LPVOID param) MSG msg; FrameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); + SetThreadName("alsoft-record"); while(GetMessage(&msg, NULL, 0, 0)) { diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index d8dbdcd9..95146c1b 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -714,6 +714,11 @@ struct ALCdevice_struct #define INVALID_OFFSET (~0u) +/* Must be less than 15 characters (16 including terminating null) for + * compatibility with pthread_setname_np limitations. */ +#define MIXER_THREAD_NAME "alsoft-mixer" + + static inline struct ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) { return (struct ALbuffer*)LookupUIntMapKey(&device->BufferMap, id); } static inline struct ALeffect *LookupEffect(ALCdevice *device, ALuint id) -- cgit v1.2.3 From 8ceb800defbf13354866cd7c6a4b676cf54aad5d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 27 Oct 2013 08:14:13 -0700 Subject: Rework threading functions --- Alc/alcThread.c | 144 ------------------------------------------ Alc/backends/alsa.c | 10 +-- Alc/backends/dsound.c | 6 +- Alc/backends/mmdevapi.c | 6 +- Alc/backends/null.c | 6 +- Alc/backends/oss.c | 12 ++-- Alc/backends/pulseaudio.c | 10 +-- Alc/backends/qsa.c | 17 +++-- Alc/backends/sndio.c | 6 +- Alc/backends/solaris.c | 9 +-- Alc/backends/wave.c | 6 +- Alc/backends/winmm.c | 1 + Alc/threads.c | 152 +++++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 2 +- OpenAL32/Include/alMain.h | 4 -- OpenAL32/Include/threads.h | 14 +++++ 16 files changed, 213 insertions(+), 192 deletions(-) delete mode 100644 Alc/alcThread.c create mode 100644 Alc/threads.c create mode 100644 OpenAL32/Include/threads.h (limited to 'Alc/backends/mmdevapi.c') diff --git a/Alc/alcThread.c b/Alc/alcThread.c deleted file mode 100644 index c2f38031..00000000 --- a/Alc/alcThread.c +++ /dev/null @@ -1,144 +0,0 @@ -/** - * OpenAL cross platform audio library - * Copyright (C) 1999-2007 by authors. - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * Or go to http://www.gnu.org/copyleft/lgpl.html - */ - -#include "config.h" - -#include - -#include "alMain.h" -#include "alThunk.h" - -#define THREAD_STACK_SIZE (1*1024*1024) /* 1MB */ - -#ifdef _WIN32 - -typedef struct { - ALuint (*func)(ALvoid*); - ALvoid *ptr; - HANDLE thread; -} ThreadInfo; - -static DWORD CALLBACK StarterFunc(void *ptr) -{ - ThreadInfo *inf = (ThreadInfo*)ptr; - ALint ret; - - ret = inf->func(inf->ptr); - ExitThread((DWORD)ret); - - return (DWORD)ret; -} - -ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr) -{ - DWORD dummy; - ThreadInfo *inf = malloc(sizeof(ThreadInfo)); - if(!inf) return 0; - - inf->func = func; - inf->ptr = ptr; - - inf->thread = CreateThread(NULL, THREAD_STACK_SIZE, StarterFunc, inf, 0, &dummy); - if(!inf->thread) - { - free(inf); - return NULL; - } - - return inf; -} - -ALuint StopThread(ALvoid *thread) -{ - ThreadInfo *inf = thread; - DWORD ret = 0; - - WaitForSingleObject(inf->thread, INFINITE); - GetExitCodeThread(inf->thread, &ret); - CloseHandle(inf->thread); - - free(inf); - - return (ALuint)ret; -} - -#else - -#include - -typedef struct { - ALuint (*func)(ALvoid*); - ALvoid *ptr; - ALuint ret; - pthread_t thread; -} ThreadInfo; - -static void *StarterFunc(void *ptr) -{ - ThreadInfo *inf = (ThreadInfo*)ptr; - inf->ret = inf->func(inf->ptr); - return NULL; -} - -ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr) -{ - pthread_attr_t attr; - ThreadInfo *inf = malloc(sizeof(ThreadInfo)); - if(!inf) return NULL; - - if(pthread_attr_init(&attr) != 0) - { - free(inf); - return NULL; - } - if(pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE) != 0) - { - pthread_attr_destroy(&attr); - free(inf); - return NULL; - } - - inf->func = func; - inf->ptr = ptr; - if(pthread_create(&inf->thread, &attr, StarterFunc, inf) != 0) - { - pthread_attr_destroy(&attr); - free(inf); - return NULL; - } - pthread_attr_destroy(&attr); - - return inf; -} - -ALuint StopThread(ALvoid *thread) -{ - ThreadInfo *inf = thread; - ALuint ret; - - pthread_join(inf->thread, NULL); - ret = inf->ret; - - free(inf); - - return ret; -} - -#endif diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index bb30dac5..c60187fa 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -26,6 +26,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #include @@ -293,7 +294,7 @@ typedef struct { snd_pcm_sframes_t last_avail; volatile int killNow; - ALvoid *thread; + althread_t thread; } alsa_data; typedef struct { @@ -849,6 +850,7 @@ error: static ALCboolean alsa_start_playback(ALCdevice *device) { alsa_data *data = (alsa_data*)device->ExtraData; + ALuint (*thread_func)(ALvoid*) = NULL; snd_pcm_hw_params_t *hp = NULL; snd_pcm_access_t access; const char *funcerr; @@ -872,7 +874,7 @@ static ALCboolean alsa_start_playback(ALCdevice *device) ERR("buffer malloc failed\n"); return ALC_FALSE; } - data->thread = StartThread(ALSANoMMapProc, device); + thread_func = ALSANoMMapProc; } else { @@ -882,9 +884,9 @@ static ALCboolean alsa_start_playback(ALCdevice *device) ERR("snd_pcm_prepare(data->pcmHandle) failed: %s\n", snd_strerror(err)); return ALC_FALSE; } - data->thread = StartThread(ALSAProc, device); + thread_func = ALSAProc; } - if(data->thread == NULL) + if(!StartThread(&data->thread, thread_func, device)) { ERR("Could not create playback thread\n"); free(data->buffer); diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index 22af15d8..f09967a0 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -34,6 +34,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #ifndef DSSPEAKER_5POINT1 # define DSSPEAKER_5POINT1 0x00000006 @@ -74,7 +75,7 @@ typedef struct { HANDLE NotifyEvent; volatile int killNow; - ALvoid *thread; + althread_t thread; } DSoundPlaybackData; typedef struct { @@ -632,8 +633,7 @@ static ALCboolean DSoundStartPlayback(ALCdevice *device) { DSoundPlaybackData *data = (DSoundPlaybackData*)device->ExtraData; - data->thread = StartThread(DSoundPlaybackProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, DSoundPlaybackProc, device)) return ALC_FALSE; return ALC_TRUE; diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index e6447bef..fb70d609 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -40,6 +40,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); @@ -69,7 +70,7 @@ typedef struct { volatile UINT32 Padding; volatile int killNow; - ALvoid *thread; + althread_t thread; } MMDevApiData; @@ -677,8 +678,7 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr) if(SUCCEEDED(hr)) { data->render = ptr; - data->thread = StartThread(MMDevApiProc, device); - if(!data->thread) + if(!StartThread(&data->thread, MMDevApiProc, device)) { if(data->render) IAudioRenderClient_Release(data->render); diff --git a/Alc/backends/null.c b/Alc/backends/null.c index 73e3e8cb..9742424c 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -27,11 +27,12 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" typedef struct { volatile int killNow; - ALvoid *thread; + althread_t thread; } null_data; @@ -112,8 +113,7 @@ static ALCboolean null_start_playback(ALCdevice *device) { null_data *data = (null_data*)device->ExtraData; - data->thread = StartThread(NullProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, NullProc, device)) return ALC_FALSE; return ALC_TRUE; diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c index 892e2327..35ae80cc 100644 --- a/Alc/backends/oss.c +++ b/Alc/backends/oss.c @@ -33,6 +33,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #include @@ -54,14 +55,15 @@ static const char *oss_capture = "/dev/dsp"; typedef struct { int fd; - volatile int killNow; - ALvoid *thread; ALubyte *mix_data; int data_size; RingBuffer *ring; int doCapture; + + volatile int killNow; + althread_t thread; } oss_data; @@ -286,8 +288,7 @@ static ALCboolean oss_start_playback(ALCdevice *device) data->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType); data->mix_data = calloc(1, data->data_size); - data->thread = StartThread(OSSProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, OSSProc, device)) { free(data->mix_data); data->mix_data = NULL; @@ -428,8 +429,7 @@ static ALCenum oss_open_capture(ALCdevice *device, const ALCchar *deviceName) data->mix_data = calloc(1, data->data_size); device->ExtraData = data; - data->thread = StartThread(OSSCaptureProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, OSSCaptureProc, device)) { device->ExtraData = NULL; free(data->mix_data); diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c index 5b6e0fad..4dc016a1 100644 --- a/Alc/backends/pulseaudio.c +++ b/Alc/backends/pulseaudio.c @@ -25,6 +25,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #include @@ -205,11 +206,11 @@ typedef struct { pa_threaded_mainloop *loop; - ALvoid *thread; - volatile ALboolean killNow; - pa_stream *stream; pa_context *context; + + volatile ALboolean killNow; + althread_t thread; } pulse_data; typedef struct { @@ -1151,8 +1152,7 @@ static ALCboolean pulse_start_playback(ALCdevice *device) { pulse_data *data = device->ExtraData; - data->thread = StartThread(PulseProc, device); - if(!data->thread) + if(!StartThread(&data->thread, PulseProc, device)) return ALC_FALSE; return ALC_TRUE; diff --git a/Alc/backends/qsa.c b/Alc/backends/qsa.c index 2890a121..d91ffb2c 100644 --- a/Alc/backends/qsa.c +++ b/Alc/backends/qsa.c @@ -31,20 +31,22 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" + typedef struct { snd_pcm_t* pcmHandle; int audio_fd; + snd_pcm_channel_setup_t csetup; + snd_pcm_channel_params_t cparams; + ALvoid* buffer; ALsizei size; volatile int killNow; - ALvoid* thread; - - snd_pcm_channel_setup_t csetup; - snd_pcm_channel_params_t cparams; + althread_t thread; } qsa_data; typedef struct @@ -619,13 +621,10 @@ static ALCboolean qsa_reset_playback(ALCdevice* device) static ALCboolean qsa_start_playback(ALCdevice* device) { - qsa_data* data=(qsa_data*)device->ExtraData; + qsa_data *data = (qsa_data*)device->ExtraData; - data->thread=StartThread(qsa_proc_playback, device); - if (data->thread==NULL) - { + if(!StartThread(&data->thread, qsa_proc_playback, device)) return ALC_FALSE; - } return ALC_TRUE; } diff --git a/Alc/backends/sndio.c b/Alc/backends/sndio.c index 4c3a5de6..d61ab3df 100644 --- a/Alc/backends/sndio.c +++ b/Alc/backends/sndio.c @@ -26,6 +26,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #include @@ -46,7 +47,7 @@ typedef struct { ALsizei data_size; volatile int killNow; - ALvoid *thread; + althread_t thread; } sndio_data; @@ -223,8 +224,7 @@ 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); - data->thread = StartThread(sndio_proc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, sndio_proc, device)) { sio_stop(data->sndHandle); free(data->mix_data); diff --git a/Alc/backends/solaris.c b/Alc/backends/solaris.c index b9288197..c6fd32e9 100644 --- a/Alc/backends/solaris.c +++ b/Alc/backends/solaris.c @@ -33,6 +33,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #include @@ -43,11 +44,12 @@ static const char *solaris_driver = "/dev/audio"; typedef struct { int fd; - volatile int killNow; - ALvoid *thread; ALubyte *mix_data; int data_size; + + volatile int killNow; + althread_t thread; } solaris_data; @@ -208,8 +210,7 @@ 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); - data->thread = StartThread(SolarisProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, SolarisProc, device)) { free(data->mix_data); data->mix_data = NULL; diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c index ce827fe8..6245ef43 100644 --- a/Alc/backends/wave.c +++ b/Alc/backends/wave.c @@ -29,6 +29,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" typedef struct { @@ -39,7 +40,7 @@ typedef struct { ALuint size; volatile int killNow; - ALvoid *thread; + althread_t thread; } wave_data; @@ -288,8 +289,7 @@ static ALCboolean wave_start_playback(ALCdevice *device) return ALC_FALSE; } - data->thread = StartThread(WaveProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, WaveProc, device)) { free(data->buffer); data->buffer = NULL; diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c index e003375c..5a64645b 100644 --- a/Alc/backends/winmm.c +++ b/Alc/backends/winmm.c @@ -29,6 +29,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #ifndef WAVE_FORMAT_IEEE_FLOAT #define WAVE_FORMAT_IEEE_FLOAT 0x0003 diff --git a/Alc/threads.c b/Alc/threads.c new file mode 100644 index 00000000..fd08b432 --- /dev/null +++ b/Alc/threads.c @@ -0,0 +1,152 @@ +/** + * OpenAL cross platform audio library + * Copyright (C) 1999-2007 by authors. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * Or go to http://www.gnu.org/copyleft/lgpl.html + */ + +#include "config.h" + +#include "threads.h" + +#include + +#include "alMain.h" +#include "alThunk.h" + +#define THREAD_STACK_SIZE (1*1024*1024) /* 1MB */ + +#ifdef _WIN32 + +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; +} + +#else + +#include + +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; +} + +#endif diff --git a/CMakeLists.txt b/CMakeLists.txt index f9efda81..3346b0e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -489,7 +489,6 @@ SET(ALC_OBJS Alc/ALc.c Alc/ALu.c Alc/alcConfig.c Alc/alcRing.c - Alc/alcThread.c Alc/bs2b.c Alc/effects/autowah.c Alc/effects/chorus.c @@ -505,6 +504,7 @@ SET(ALC_OBJS Alc/ALc.c Alc/helpers.c Alc/hrtf.c Alc/panning.c + Alc/threads.c Alc/mixer.c Alc/mixer_c.c ) diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 95146c1b..bfe575bd 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -815,10 +815,6 @@ typedef struct { void SetMixerFPUMode(FPUCtl *ctl); void RestoreFPUMode(const FPUCtl *ctl); -ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr); -ALuint StopThread(ALvoid *thread); - -void SetThreadName(const char *name); typedef struct RingBuffer RingBuffer; RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length); diff --git a/OpenAL32/Include/threads.h b/OpenAL32/Include/threads.h new file mode 100644 index 00000000..26493101 --- /dev/null +++ b/OpenAL32/Include/threads.h @@ -0,0 +1,14 @@ +#ifndef AL_THREADS_H +#define AL_THREADS_H + +#include "alMain.h" + +struct althread_info; +typedef struct althread_info* althread_t; + +ALboolean StartThread(althread_t *out, ALuint (*func)(ALvoid*), ALvoid *ptr); +ALuint StopThread(althread_t thread); + +void SetThreadName(const char *name); + +#endif /* AL_THREADS_H */ -- cgit v1.2.3 From f24cb447818ea21ff5a5d80d6396abb4723fd2ed Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 28 Oct 2013 12:05:33 -0700 Subject: Move the device mutex to the backend --- Alc/ALc.c | 53 +++++++++++++++++++++++++++++++++-------------- Alc/alcRing.c | 1 + Alc/backends/alsa.c | 1 + Alc/backends/base.h | 5 +++++ Alc/backends/dsound.c | 1 + Alc/backends/mmdevapi.c | 1 + Alc/backends/null.c | 11 ++++++++-- Alc/backends/oss.c | 1 + Alc/backends/pulseaudio.c | 1 + Alc/backends/solaris.c | 1 + Alc/backends/wave.c | 1 + Alc/helpers.c | 2 ++ Alc/threads.c | 3 +++ OpenAL32/Include/alMain.h | 4 ---- OpenAL32/alError.c | 5 +++++ 15 files changed, 70 insertions(+), 21 deletions(-) (limited to 'Alc/backends/mmdevapi.c') diff --git a/Alc/ALc.c b/Alc/ALc.c index 2cbc7331..18ccb5e7 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -114,8 +114,14 @@ typedef struct BackendWrapper { } BackendWrapper; #define BACKENDWRAPPER_INITIALIZER { { GET_VTABLE2(ALCbackend, BackendWrapper) } } -static void BackendWrapper_Destruct(BackendWrapper* UNUSED(self)) +static void BackendWrapper_Construct(BackendWrapper *self, ALCdevice *device) { + ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); +} + +static void BackendWrapper_Destruct(BackendWrapper *self) +{ + ALCbackend_Destruct(STATIC_CAST(ALCbackend, self)); } static ALCenum BackendWrapper_open(BackendWrapper *self, const ALCchar *name) @@ -182,7 +188,7 @@ ALCbackend *create_backend_wrapper(ALCdevice *device) if(!backend) return NULL; SET_VTABLE2(BackendWrapper, ALCbackend, backend); - STATIC_CAST(ALCbackend, backend)->mDevice = device; + BackendWrapper_Construct(backend, device); return STATIC_CAST(ALCbackend, backend); } @@ -1466,11 +1472,11 @@ static ALCboolean IsValidALCChannels(ALCenum channels) void ALCdevice_LockDefault(ALCdevice *device) { - EnterCriticalSection(&device->Mutex); + ALCbackend_lock(device->Backend); } void ALCdevice_UnlockDefault(ALCdevice *device) { - LeaveCriticalSection(&device->Mutex); + ALCbackend_unlock(device->Backend); } ALint64 ALCdevice_GetLatencyDefault(ALCdevice *UNUSED(device)) { @@ -1504,6 +1510,18 @@ void UnlockContext(ALCcontext *context) } +/* These should go to a seaparate source. */ +void ALCbackend_Construct(ALCbackend *self, ALCdevice *device) +{ + self->mDevice = device; + InitializeCriticalSection(&self->mMutex); +} + +void ALCbackend_Destruct(ALCbackend *self) +{ + DeleteCriticalSection(&self->mMutex); +} + ALint64 ALCbackend_getLatency(ALCbackend* UNUSED(self)) { return 0; @@ -1511,12 +1529,12 @@ ALint64 ALCbackend_getLatency(ALCbackend* UNUSED(self)) void ALCbackend_lock(ALCbackend *self) { - ALCdevice_LockDefault(self->mDevice); + EnterCriticalSection(&self->mMutex); } void ALCbackend_unlock(ALCbackend *self) { - ALCdevice_UnlockDefault(self->mDevice); + LeaveCriticalSection(&self->mMutex); } @@ -2046,8 +2064,6 @@ static ALCvoid FreeDevice(ALCdevice *device) free(device->DeviceName); device->DeviceName = NULL; - DeleteCriticalSection(&device->Mutex); - al_free(device); } @@ -2963,7 +2979,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) device->ref = 1; device->Connected = ALC_TRUE; device->Type = Playback; - InitializeCriticalSection(&device->Mutex); device->LastError = ALC_NO_ERROR; device->Flags = 0; @@ -2997,7 +3012,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) } if(!device->Backend) { - DeleteCriticalSection(&device->Mutex); al_free(device); alcSetError(NULL, ALC_OUT_OF_MEMORY); return NULL; @@ -3143,7 +3157,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) if((err=VCALL(device->Backend,open)(deviceName)) != ALC_NO_ERROR) { DELETE_OBJ(device->Backend); - DeleteCriticalSection(&device->Mutex); al_free(device); alcSetError(NULL, err); return NULL; @@ -3250,7 +3263,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, device->ref = 1; device->Connected = ALC_TRUE; device->Type = Capture; - InitializeCriticalSection(&device->Mutex); InitUIntMap(&device->BufferMap, ~0); InitUIntMap(&device->EffectMap, ~0); @@ -3258,13 +3270,20 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, device->DeviceName = NULL; + device->Backend = create_backend_wrapper(device); + if(!device->Backend) + { + al_free(device); + alcSetError(NULL, ALC_OUT_OF_MEMORY); + return NULL; + } + device->Flags |= DEVICE_FREQUENCY_REQUEST; device->Frequency = frequency; device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_SAMPLE_TYPE_REQUEST; if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE) { - DeleteCriticalSection(&device->Mutex); al_free(device); alcSetError(NULL, ALC_INVALID_ENUM); return NULL; @@ -3275,7 +3294,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, if((err=ALCdevice_OpenCapture(device, deviceName)) != ALC_NO_ERROR) { - DeleteCriticalSection(&device->Mutex); al_free(device); alcSetError(NULL, err); return NULL; @@ -3401,7 +3419,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN device->ref = 1; device->Connected = ALC_TRUE; device->Type = Loopback; - InitializeCriticalSection(&device->Mutex); device->LastError = ALC_NO_ERROR; device->Flags = 0; @@ -3420,6 +3437,12 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN InitUIntMap(&device->FilterMap, ~0); device->Backend = create_backend_wrapper(device); + if(!device->Backend) + { + al_free(device); + alcSetError(NULL, ALC_OUT_OF_MEMORY); + return NULL; + } //Set output format device->NumUpdates = 0; diff --git a/Alc/alcRing.c b/Alc/alcRing.c index 2d9d5069..f831860f 100644 --- a/Alc/alcRing.c +++ b/Alc/alcRing.c @@ -24,6 +24,7 @@ #include #include "alMain.h" +#include "compat.h" struct RingBuffer { diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index c60187fa..0e0b4436 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -27,6 +27,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #include diff --git a/Alc/backends/base.h b/Alc/backends/base.h index 272a3f65..22602b23 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.h @@ -2,6 +2,7 @@ #define AL_BACKENDS_BASE_H #include "alMain.h" +#include "compat.h" struct ALCbackendVtable; @@ -10,8 +11,12 @@ typedef struct ALCbackend { const struct ALCbackendVtable *vtbl; ALCdevice *mDevice; + + CRITICAL_SECTION mMutex; } ALCbackend; +void ALCbackend_Construct(ALCbackend *self, ALCdevice *device); +void ALCbackend_Destruct(ALCbackend *self); ALint64 ALCbackend_getLatency(ALCbackend *self); void ALCbackend_lock(ALCbackend *self); void ALCbackend_unlock(ALCbackend *self); diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index f09967a0..9fa4bd61 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -35,6 +35,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #ifndef DSSPEAKER_5POINT1 # define DSSPEAKER_5POINT1 0x00000006 diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index fb70d609..31be2ed1 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -41,6 +41,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); diff --git a/Alc/backends/null.c b/Alc/backends/null.c index d21ebf0c..af68c585 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -28,6 +28,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #include "backends/base.h" @@ -85,8 +86,14 @@ static ALuint ALCnullBackend_mixerProc(ALvoid *ptr) } -static void ALCnullBackend_Destruct(ALCnullBackend* UNUSED(self)) +static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device) { + ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); +} + +static void ALCnullBackend_Destruct(ALCnullBackend *self) +{ + ALCbackend_Destruct(STATIC_CAST(ALCbackend, self)); } static ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name) @@ -197,7 +204,7 @@ ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UNUSED(se if(!backend) return NULL; SET_VTABLE2(ALCnullBackend, ALCbackend, backend); - STATIC_CAST(ALCbackend, backend)->mDevice = device; + ALCnullBackend_Construct(backend, device); return STATIC_CAST(ALCbackend, backend); } diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c index 35ae80cc..a9510a35 100644 --- a/Alc/backends/oss.c +++ b/Alc/backends/oss.c @@ -34,6 +34,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #include diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c index 4dc016a1..c24b86e2 100644 --- a/Alc/backends/pulseaudio.c +++ b/Alc/backends/pulseaudio.c @@ -26,6 +26,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #include diff --git a/Alc/backends/solaris.c b/Alc/backends/solaris.c index c6fd32e9..c4d40273 100644 --- a/Alc/backends/solaris.c +++ b/Alc/backends/solaris.c @@ -34,6 +34,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #include diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c index e7698430..ec88862b 100644 --- a/Alc/backends/wave.c +++ b/Alc/backends/wave.c @@ -31,6 +31,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" typedef struct { diff --git a/Alc/helpers.c b/Alc/helpers.c index 4d715553..6681fde7 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -344,6 +344,8 @@ WCHAR *strdupW(const WCHAR *str) #include #endif #include +#include +#include void InitializeCriticalSection(CRITICAL_SECTION *cs) { diff --git a/Alc/threads.c b/Alc/threads.c index 1f7e3a6c..1c422949 100644 --- a/Alc/threads.c +++ b/Alc/threads.c @@ -32,6 +32,9 @@ #ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include + typedef struct althread_info { ALuint (*func)(ALvoid*); ALvoid *ptr; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index ebedada8..a02c71b6 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -15,8 +15,6 @@ #include "AL/alc.h" #include "AL/alext.h" -#include "compat.h" - #ifndef ALC_SOFT_HRTF #define ALC_SOFT_HRTF 1 #define ALC_HRTF_SOFT 0x1992 @@ -554,8 +552,6 @@ struct ALCdevice_struct ALCboolean Connected; enum DeviceType Type; - CRITICAL_SECTION Mutex; - ALuint Frequency; ALuint UpdateSize; ALuint NumUpdates; diff --git a/OpenAL32/alError.c b/OpenAL32/alError.c index d18c1867..b557532e 100644 --- a/OpenAL32/alError.c +++ b/OpenAL32/alError.c @@ -22,6 +22,11 @@ #include +#ifdef HAVE_WINDOWS_H +#define WIN32_LEAN_AND_MEAN +#include +#endif + #include "alMain.h" #include "AL/alc.h" #include "alError.h" -- cgit v1.2.3 From 10dbb1bc9b5d5040cb363c5a0dccb8ad273052b9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 4 Nov 2013 23:34:18 -0800 Subject: Remove the Lock and Unlock methods from BackendFuncs All backends that still use the old interface use the default locking methods, which is also used by the ALCbackend base. --- Alc/ALc.c | 16 +++------------- Alc/backends/base.c | 32 ++++---------------------------- Alc/backends/coreaudio.c | 2 -- Alc/backends/dsound.c | 2 -- Alc/backends/mmdevapi.c | 2 -- Alc/backends/opensl.c | 2 -- Alc/backends/portaudio.c | 2 -- Alc/backends/qsa.c | 2 -- Alc/backends/sndio.c | 2 -- Alc/backends/solaris.c | 2 -- Alc/backends/wave.c | 2 -- Alc/backends/winmm.c | 2 -- OpenAL32/Include/alMain.h | 5 ----- 13 files changed, 7 insertions(+), 66 deletions(-) (limited to 'Alc/backends/mmdevapi.c') diff --git a/Alc/ALc.c b/Alc/ALc.c index bb611a77..2effb854 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -53,7 +53,7 @@ struct BackendInfo { BackendFuncs Funcs; }; -#define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } +#define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } static struct BackendInfo BackendList[] = { #ifdef HAVE_PULSEAUDIO { "pulse", ALCpulseBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs }, @@ -1386,21 +1386,14 @@ static ALCboolean IsValidALCChannels(ALCenum channels) /************************************************ * Miscellaneous ALC helpers ************************************************/ +extern inline void LockContext(ALCcontext *context); +extern inline void UnlockContext(ALCcontext *context); -void ALCdevice_LockDefault(ALCdevice *device) -{ - ALCbackend_lock(device->Backend); -} -void ALCdevice_UnlockDefault(ALCdevice *device) -{ - ALCbackend_unlock(device->Backend); -} ALint64 ALCdevice_GetLatencyDefault(ALCdevice *UNUSED(device)) { return 0; } - ALint64 ALCdevice_GetLatency(ALCdevice *device) { return V0(device->Backend,getLatency)(); @@ -1416,9 +1409,6 @@ void ALCdevice_Unlock(ALCdevice *device) V0(device->Backend,unlock)(); } -extern inline void LockContext(ALCcontext *context); -extern inline void UnlockContext(ALCcontext *context); - /* SetDefaultWFXChannelOrder * diff --git a/Alc/backends/base.c b/Alc/backends/base.c index a6163c08..d9ef3e99 100644 --- a/Alc/backends/base.c +++ b/Alc/backends/base.c @@ -72,8 +72,8 @@ static void PlaybackWrapper_stop(PlaybackWrapper *self); static DECLARE_FORWARD2(PlaybackWrapper, ALCbackend, ALCenum, captureSamples, void*, ALCuint) static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, ALCuint, availableSamples) static ALint64 PlaybackWrapper_getLatency(PlaybackWrapper *self); -static void PlaybackWrapper_lock(PlaybackWrapper *self); -static void PlaybackWrapper_unlock(PlaybackWrapper *self); +static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, lock) +static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, unlock) static void PlaybackWrapper_Delete(PlaybackWrapper *self); DEFINE_ALCBACKEND_VTABLE(PlaybackWrapper); @@ -119,18 +119,6 @@ static ALint64 PlaybackWrapper_getLatency(PlaybackWrapper *self) return device->Funcs->GetLatency(device); } -static void PlaybackWrapper_lock(PlaybackWrapper *self) -{ - ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; - device->Funcs->Lock(device); -} - -static void PlaybackWrapper_unlock(PlaybackWrapper *self) -{ - ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; - device->Funcs->Unlock(device); -} - static void PlaybackWrapper_Delete(PlaybackWrapper *self) { free(self); @@ -151,8 +139,8 @@ static void CaptureWrapper_stop(CaptureWrapper *self); ALCenum CaptureWrapper_captureSamples(CaptureWrapper *self, void *buffer, ALCuint samples); ALCuint CaptureWrapper_availableSamples(CaptureWrapper *self); static ALint64 CaptureWrapper_getLatency(CaptureWrapper *self); -static void CaptureWrapper_lock(CaptureWrapper *self); -static void CaptureWrapper_unlock(CaptureWrapper *self); +static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, lock) +static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, unlock) static void CaptureWrapper_Delete(CaptureWrapper *self); DEFINE_ALCBACKEND_VTABLE(CaptureWrapper); @@ -206,18 +194,6 @@ static ALint64 CaptureWrapper_getLatency(CaptureWrapper *self) return device->Funcs->GetLatency(device); } -static void CaptureWrapper_lock(CaptureWrapper *self) -{ - ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; - device->Funcs->Lock(device); -} - -static void CaptureWrapper_unlock(CaptureWrapper *self) -{ - ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; - device->Funcs->Unlock(device); -} - static void CaptureWrapper_Delete(CaptureWrapper *self) { free(self); diff --git a/Alc/backends/coreaudio.c b/Alc/backends/coreaudio.c index 150f37ac..5c9b69c8 100644 --- a/Alc/backends/coreaudio.c +++ b/Alc/backends/coreaudio.c @@ -677,8 +677,6 @@ static const BackendFuncs ca_funcs = { ca_stop_capture, ca_capture_samples, ca_available_samples, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, ALCdevice_GetLatencyDefault }; diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index 9fa4bd61..0c4f816b 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -955,8 +955,6 @@ static const BackendFuncs DSoundFuncs = { DSoundStopCapture, DSoundCaptureSamples, DSoundAvailableSamples, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, ALCdevice_GetLatencyDefault }; diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index 31be2ed1..8bbbbddb 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -968,8 +968,6 @@ static const BackendFuncs MMDevApiFuncs = { NULL, NULL, NULL, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, MMDevApiGetLatency }; diff --git a/Alc/backends/opensl.c b/Alc/backends/opensl.c index 1a104029..4e260879 100644 --- a/Alc/backends/opensl.c +++ b/Alc/backends/opensl.c @@ -420,8 +420,6 @@ static const BackendFuncs opensl_funcs = { NULL, NULL, NULL, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, ALCdevice_GetLatencyDefault }; diff --git a/Alc/backends/portaudio.c b/Alc/backends/portaudio.c index fde1f59d..162788fc 100644 --- a/Alc/backends/portaudio.c +++ b/Alc/backends/portaudio.c @@ -427,8 +427,6 @@ static const BackendFuncs pa_funcs = { pa_stop_capture, pa_capture_samples, pa_available_samples, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, ALCdevice_GetLatencyDefault }; diff --git a/Alc/backends/qsa.c b/Alc/backends/qsa.c index d91ffb2c..ae3ace61 100644 --- a/Alc/backends/qsa.c +++ b/Alc/backends/qsa.c @@ -1109,8 +1109,6 @@ BackendFuncs qsa_funcs= qsa_stop_capture, qsa_capture_samples, qsa_available_samples, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, qsa_get_latency, }; diff --git a/Alc/backends/sndio.c b/Alc/backends/sndio.c index d61ab3df..80aebfd1 100644 --- a/Alc/backends/sndio.c +++ b/Alc/backends/sndio.c @@ -267,8 +267,6 @@ static const BackendFuncs sndio_funcs = { NULL, NULL, NULL, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, ALCdevice_GetLatencyDefault }; diff --git a/Alc/backends/solaris.c b/Alc/backends/solaris.c index c4d40273..700131c8 100644 --- a/Alc/backends/solaris.c +++ b/Alc/backends/solaris.c @@ -253,8 +253,6 @@ static const BackendFuncs solaris_funcs = { NULL, NULL, NULL, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, ALCdevice_GetLatencyDefault }; diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c index ec88862b..2fafc4b9 100644 --- a/Alc/backends/wave.c +++ b/Alc/backends/wave.c @@ -343,8 +343,6 @@ static const BackendFuncs wave_funcs = { NULL, NULL, NULL, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, ALCdevice_GetLatencyDefault }; diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c index 5a64645b..f268aca7 100644 --- a/Alc/backends/winmm.c +++ b/Alc/backends/winmm.c @@ -713,8 +713,6 @@ static const BackendFuncs WinMMFuncs = { WinMMStopCapture, WinMMCaptureSamples, WinMMAvailableSamples, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, ALCdevice_GetLatencyDefault }; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 2af21017..095a4a2c 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -201,9 +201,6 @@ typedef struct { ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint); ALCuint (*AvailableSamples)(ALCdevice*); - void (*Lock)(ALCdevice*); - void (*Unlock)(ALCdevice*); - ALint64 (*GetLatency)(ALCdevice*); } BackendFuncs; @@ -475,8 +472,6 @@ void ALCcontext_DecRef(ALCcontext *context); void AppendAllDevicesList(const ALCchar *name); void AppendCaptureDeviceList(const ALCchar *name); -void ALCdevice_LockDefault(ALCdevice *device); -void ALCdevice_UnlockDefault(ALCdevice *device); ALint64 ALCdevice_GetLatencyDefault(ALCdevice *device); void ALCdevice_Lock(ALCdevice *device); -- cgit v1.2.3 From 80ea801204cec06b26ac8823747ad0981165822c Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 25 Nov 2013 17:29:39 -0800 Subject: Add a macro for GCC to ensure stack alignment --- Alc/ALc.c | 2 +- Alc/backends/dsound.c | 2 +- Alc/backends/mmdevapi.c | 2 +- Alc/backends/qsa.c | 11 ++--------- Alc/backends/winmm.c | 2 +- OpenAL32/Include/alMain.h | 10 ++++++++++ 6 files changed, 16 insertions(+), 13 deletions(-) (limited to 'Alc/backends/mmdevapi.c') diff --git a/Alc/ALc.c b/Alc/ALc.c index 2effb854..a4e2e95e 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -3383,7 +3383,7 @@ ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupportedSOFT(ALCdevice *device * Renders some samples into a buffer, using the format last set by the * attributes given to alcCreateContext. */ -ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffer, ALCsizei samples) +FORCE_ALIGN ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffer, ALCsizei samples) { if(!(device=VerifyDevice(device)) || device->Type != Loopback) alcSetError(device, ALC_INVALID_DEVICE); diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index 0c4f816b..6b108fba 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -224,7 +224,7 @@ static BOOL CALLBACK DSoundEnumCaptureDevices(LPGUID guid, LPCSTR desc, LPCSTR U } -static ALuint DSoundPlaybackProc(ALvoid *ptr) +FORCE_ALIGN static ALuint DSoundPlaybackProc(ALvoid *ptr) { ALCdevice *Device = (ALCdevice*)ptr; DSoundPlaybackData *data = (DSoundPlaybackData*)Device->ExtraData; diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index 8bbbbddb..fa7c54f9 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -220,7 +220,7 @@ static DevMap *ProbeDevices(IMMDeviceEnumerator *devenum, EDataFlow flowdir, ALu } -static ALuint MMDevApiProc(ALvoid *ptr) +FORCE_ALIGN static ALuint MMDevApiProc(ALvoid *ptr) { ALCdevice *device = ptr; MMDevApiData *data = device->ExtraData; diff --git a/Alc/backends/qsa.c b/Alc/backends/qsa.c index ae3ace61..c9762f85 100644 --- a/Alc/backends/qsa.c +++ b/Alc/backends/qsa.c @@ -177,15 +177,8 @@ static DevMap* deviceList(int type, ALuint* count) return dev_list; } -/* force_align_arg_pointer is required for proper function arguments */ -/* aligning, when SSE mixer is used. QNX has a bug in pthread_create */ -/* function regarding thread stack alignment, it uses 64 bit align */ -/* instead of 128 bit, like main thread. */ -#if defined(__GNUC__) && (_NTO_VERSION <= 650) && \ - defined(__i386__) && defined(HAVE_SSE) -__attribute__((force_align_arg_pointer)) -#endif /* __GNUC__ && QNX version < 6.5.0 on x86 platform with SSE support */ -static ALuint qsa_proc_playback(ALvoid* ptr) + +FORCE_ALIGN static ALuint qsa_proc_playback(ALvoid* ptr) { ALCdevice* device=(ALCdevice*)ptr; qsa_data* data=(qsa_data*)device->ExtraData; diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c index f268aca7..7082a874 100644 --- a/Alc/backends/winmm.c +++ b/Alc/backends/winmm.c @@ -165,7 +165,7 @@ static void CALLBACK WaveOutProc(HWAVEOUT UNUSED(device), UINT msg, DWORD_PTR in Used by "MMSYSTEM" Device. Called when a WaveOut buffer has used up its audio data. */ -static DWORD WINAPI PlaybackThreadProc(LPVOID param) +FORCE_ALIGN static DWORD WINAPI PlaybackThreadProc(LPVOID param) { ALCdevice *Device = (ALCdevice*)param; WinMMData *data = Device->ExtraData; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index cc631935..e0753ea8 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -74,6 +74,16 @@ typedef ptrdiff_t ALsizeiptrEXT; #define PRINTF_STYLE(x, y) #endif +#if defined(__GNUC__) && defined(__i386__) +/* force_align_arg_pointer is required for proper function arguments aligning + * when SSE code is used. Some systems (Windows, QNX) do not guarantee our + * thread functions will be properly aligned on the stack, even though GCC may + * generate code with the assumption that it is. */ +#define FORCE_ALIGN __attribute__((force_align_arg_pointer)) +#else +#define FORCE_ALIGN +#endif + static const union { ALuint u; -- cgit v1.2.3