diff options
-rw-r--r-- | Alc/alc.cpp | 64 | ||||
-rw-r--r-- | Alc/backends/alsa.cpp | 4 | ||||
-rw-r--r-- | Alc/backends/dsound.cpp | 6 | ||||
-rw-r--r-- | Alc/backends/jack.cpp | 3 | ||||
-rw-r--r-- | Alc/backends/opensl.cpp | 4 | ||||
-rw-r--r-- | Alc/backends/oss.cpp | 4 | ||||
-rw-r--r-- | Alc/backends/sndio.cpp | 4 | ||||
-rw-r--r-- | Alc/backends/wasapi.cpp | 10 | ||||
-rw-r--r-- | Alc/backends/wave.cpp | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 6 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 2 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.cpp | 4 | ||||
-rw-r--r-- | OpenAL32/alSource.cpp | 4 |
13 files changed, 38 insertions, 79 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 167ee3e6..b74f4918 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2844,7 +2844,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *Device, ALCenum para alcSetError(nullptr, ALC_INVALID_DEVICE); else { - std::lock_guard<std::mutex> _{dev->BackendLock}; + std::lock_guard<std::mutex> _{dev->StateLock}; value = (dev->mHrtf ? dev->HrtfName.c_str() : ""); } break; @@ -2927,7 +2927,7 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC alcSetError(device, ALC_INVALID_VALUE); else { - std::lock_guard<std::mutex> _{device->BackendLock}; + std::lock_guard<std::mutex> _{device->StateLock}; values[i++] = ALC_MAJOR_VERSION; values[i++] = alcMajorVersion; values[i++] = ALC_MINOR_VERSION; @@ -2948,13 +2948,13 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC return 1; case ALC_CAPTURE_SAMPLES: - { std::lock_guard<std::mutex> _{device->BackendLock}; + { std::lock_guard<std::mutex> _{device->StateLock}; values[0] = device->Backend->availableSamples(); } return 1; case ALC_CONNECTED: - { std::lock_guard<std::mutex> _{device->BackendLock}; + { std::lock_guard<std::mutex> _{device->StateLock}; values[0] = device->Connected.load(std::memory_order_acquire); } return 1; @@ -2979,7 +2979,7 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC alcSetError(device, ALC_INVALID_VALUE); else { - std::lock_guard<std::mutex> _{device->BackendLock}; + std::lock_guard<std::mutex> _{device->StateLock}; values[i++] = ALC_MAJOR_VERSION; values[i++] = alcMajorVersion; values[i++] = ALC_MINOR_VERSION; @@ -3071,7 +3071,7 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC alcSetError(device, ALC_INVALID_DEVICE); return 0; } - { std::lock_guard<std::mutex> _{device->BackendLock}; + { std::lock_guard<std::mutex> _{device->StateLock}; values[0] = device->Frequency / device->UpdateSize; } return 1; @@ -3143,7 +3143,7 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC return 1; case ALC_CONNECTED: - { std::lock_guard<std::mutex> _{device->BackendLock}; + { std::lock_guard<std::mutex> _{device->StateLock}; values[0] = device->Connected.load(std::memory_order_acquire); } return 1; @@ -3157,7 +3157,7 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC return 1; case ALC_NUM_HRTF_SPECIFIERS_SOFT: - { std::lock_guard<std::mutex> _{device->BackendLock}; + { std::lock_guard<std::mutex> _{device->StateLock}; device->HrtfList.clear(); device->HrtfList = EnumerateHrtf(device->DeviceName.c_str()); values[0] = (ALCint)device->HrtfList.size(); @@ -3217,7 +3217,7 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname, else { ALsizei i{0}; - std::lock_guard<std::mutex> _{dev->BackendLock}; + std::lock_guard<std::mutex> _{dev->StateLock}; values[i++] = ALC_FREQUENCY; values[i++] = dev->Frequency; @@ -3280,7 +3280,7 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname, break; case ALC_DEVICE_CLOCK_SOFT: - { std::lock_guard<std::mutex> _{dev->BackendLock}; + { std::lock_guard<std::mutex> _{dev->StateLock}; using std::chrono::seconds; using std::chrono::nanoseconds; using std::chrono::duration_cast; @@ -3300,7 +3300,7 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname, break; case ALC_DEVICE_LATENCY_SOFT: - { std::lock_guard<std::mutex> _{dev->BackendLock}; + { std::lock_guard<std::mutex> _{dev->StateLock}; ClockLatency clock{GetClockLatency(dev.get())}; *values = clock.Latency.count(); } @@ -3311,7 +3311,7 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname, alcSetError(dev.get(), ALC_INVALID_VALUE); else { - std::lock_guard<std::mutex> _{dev->BackendLock}; + std::lock_guard<std::mutex> _{dev->StateLock}; ClockLatency clock{GetClockLatency(dev.get())}; values[0] = clock.ClockTime.count(); values[1] = clock.Latency.count(); @@ -3417,8 +3417,8 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin ALfloat valf; ALCenum err; - /* Explicitly hold the list lock while taking the BackendLock in case the - * device is asynchronously destropyed, to ensure this new context is + /* Explicitly hold the list lock while taking the StateLock in case the + * device is asynchronously destroyed, to ensure this new context is * properly cleaned up after being made. */ std::unique_lock<std::recursive_mutex> listlock{ListLock}; @@ -3429,7 +3429,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin alcSetError(dev.get(), ALC_INVALID_DEVICE); return nullptr; } - std::unique_lock<std::mutex> backlock{dev->BackendLock}; + std::unique_lock<std::mutex> statelock{dev->StateLock}; listlock.unlock(); dev->LastError.store(ALC_NO_ERROR); @@ -3441,12 +3441,8 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin { alcSetError(dev.get(), err); if(err == ALC_INVALID_DEVICE) - { - dev->Backend->lock(); aluHandleDisconnect(dev.get(), "Device update failure"); - dev->Backend->unlock(); - } - backlock.unlock(); + statelock.unlock(); delete ALContext; ALContext = nullptr; @@ -3490,7 +3486,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin ALContext->next.store(head, std::memory_order_relaxed); } while(!dev->ContextList.compare_exchange_weak(head, ALContext)); } - backlock.unlock(); + statelock.unlock(); if(ALContext->DefaultSlot) { @@ -3522,7 +3518,7 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) ALCdevice* Device{ctx->Device}; if(Device) { - std::lock_guard<std::mutex> _{Device->BackendLock}; + std::lock_guard<std::mutex> _{Device->StateLock}; if(!ReleaseContext(ctx.get(), Device)) { Device->Backend->stop(); @@ -3845,7 +3841,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device) alcSetError(iter, ALC_INVALID_DEVICE); return ALC_FALSE; } - std::unique_lock<std::mutex> backlock{device->BackendLock}; + std::unique_lock<std::mutex> statelock{device->StateLock}; ALCdevice *origdev{device}; ALCdevice *nextdev{device->next.load(std::memory_order_relaxed)}; @@ -3870,7 +3866,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device) if((device->Flags&DEVICE_RUNNING)) device->Backend->stop(); device->Flags &= ~DEVICE_RUNNING; - backlock.unlock(); + statelock.unlock(); ALCdevice_DecRef(device); @@ -3976,7 +3972,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device) } listlock.unlock(); - { std::lock_guard<std::mutex> _{device->BackendLock}; + { std::lock_guard<std::mutex> _{device->StateLock}; if((device->Flags&DEVICE_RUNNING)) device->Backend->stop(); device->Flags &= ~DEVICE_RUNNING; @@ -3996,7 +3992,7 @@ ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device) return; } - std::lock_guard<std::mutex> _{dev->BackendLock}; + std::lock_guard<std::mutex> _{dev->StateLock}; if(!dev->Connected.load(std::memory_order_acquire)) alcSetError(dev.get(), ALC_INVALID_DEVICE); else if(!(dev->Flags&DEVICE_RUNNING)) @@ -4018,7 +4014,7 @@ ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device) alcSetError(dev.get(), ALC_INVALID_DEVICE); else { - std::lock_guard<std::mutex> _{dev->BackendLock}; + std::lock_guard<std::mutex> _{dev->StateLock}; if((dev->Flags&DEVICE_RUNNING)) dev->Backend->stop(); dev->Flags &= ~DEVICE_RUNNING; @@ -4035,7 +4031,7 @@ ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, } ALCenum err{ALC_INVALID_VALUE}; - { std::lock_guard<std::mutex> _{dev->BackendLock}; + { std::lock_guard<std::mutex> _{dev->StateLock}; BackendBase *backend{dev->Backend.get()}; if(samples >= 0 && backend->availableSamples() >= (ALCuint)samples) err = backend->captureSamples(buffer, samples); @@ -4172,7 +4168,7 @@ ALC_API void ALC_APIENTRY alcDevicePauseSOFT(ALCdevice *device) alcSetError(dev.get(), ALC_INVALID_DEVICE); else { - std::lock_guard<std::mutex> _{dev->BackendLock}; + std::lock_guard<std::mutex> _{dev->StateLock}; if((dev->Flags&DEVICE_RUNNING)) dev->Backend->stop(); dev->Flags &= ~DEVICE_RUNNING; @@ -4193,7 +4189,7 @@ ALC_API void ALC_APIENTRY alcDeviceResumeSOFT(ALCdevice *device) return; } - std::lock_guard<std::mutex> _{dev->BackendLock}; + std::lock_guard<std::mutex> _{dev->StateLock}; if(!(dev->Flags&DEVICE_PAUSED)) return; dev->Flags &= ~DEVICE_PAUSED; @@ -4202,9 +4198,7 @@ ALC_API void ALC_APIENTRY alcDeviceResumeSOFT(ALCdevice *device) if(dev->Backend->start() == ALC_FALSE) { - dev->Backend->lock(); aluHandleDisconnect(dev.get(), "Device start failure"); - dev->Backend->unlock(); alcSetError(dev.get(), ALC_INVALID_DEVICE); return; } @@ -4255,7 +4249,7 @@ ALC_API ALCboolean ALC_APIENTRY alcResetDeviceSOFT(ALCdevice *device, const ALCi alcSetError(dev.get(), ALC_INVALID_DEVICE); return ALC_FALSE; } - std::lock_guard<std::mutex> _{dev->BackendLock}; + std::lock_guard<std::mutex> _{dev->StateLock}; listlock.unlock(); /* Force the backend to stop mixing first since we're resetting. Also reset @@ -4271,10 +4265,6 @@ ALC_API ALCboolean ALC_APIENTRY alcResetDeviceSOFT(ALCdevice *device, const ALCi alcSetError(dev.get(), err); if(err == ALC_INVALID_DEVICE) - { - dev->Backend->lock(); aluHandleDisconnect(dev.get(), "Device start failure"); - dev->Backend->unlock(); - } return ALC_FALSE; } diff --git a/Alc/backends/alsa.cpp b/Alc/backends/alsa.cpp index 43336026..a3c30732 100644 --- a/Alc/backends/alsa.cpp +++ b/Alc/backends/alsa.cpp @@ -469,9 +469,7 @@ int AlsaPlayback::mixerProc() if(state < 0) { ERR("Invalid state detected: %s\n", snd_strerror(state)); - lock(); aluHandleDisconnect(mDevice, "Bad state: %s", snd_strerror(state)); - unlock(); break; } @@ -554,9 +552,7 @@ int AlsaPlayback::mixerNoMMapProc() if(state < 0) { ERR("Invalid state detected: %s\n", snd_strerror(state)); - lock(); aluHandleDisconnect(mDevice, "Bad state: %s", snd_strerror(state)); - unlock(); break; } diff --git a/Alc/backends/dsound.cpp b/Alc/backends/dsound.cpp index b7424473..4138c180 100644 --- a/Alc/backends/dsound.cpp +++ b/Alc/backends/dsound.cpp @@ -241,9 +241,7 @@ FORCE_ALIGN int DSoundPlayback::mixerProc() if(FAILED(err)) { ERR("Failed to get buffer caps: 0x%lx\n", err); - lock(); aluHandleDisconnect(mDevice, "Failure retrieving playback buffer info: 0x%lx", err); - unlock(); return 1; } @@ -269,9 +267,7 @@ FORCE_ALIGN int DSoundPlayback::mixerProc() if(FAILED(err)) { ERR("Failed to play buffer: 0x%lx\n", err); - lock(); aluHandleDisconnect(mDevice, "Failure starting playback: 0x%lx", err); - unlock(); return 1; } Playing = true; @@ -316,9 +312,7 @@ FORCE_ALIGN int DSoundPlayback::mixerProc() else { ERR("Buffer lock error: %#lx\n", err); - lock(); aluHandleDisconnect(mDevice, "Failed to lock output buffer: 0x%lx", err); - unlock(); return 1; } diff --git a/Alc/backends/jack.cpp b/Alc/backends/jack.cpp index 5ac0ff4d..78de2699 100644 --- a/Alc/backends/jack.cpp +++ b/Alc/backends/jack.cpp @@ -200,7 +200,7 @@ int JackPlayback::bufferSizeNotifyC(jack_nframes_t numframes, void *arg) int JackPlayback::bufferSizeNotify(jack_nframes_t numframes) { - lock(); + std::lock_guard<std::mutex> _{mDevice->StateLock}; mDevice->UpdateSize = numframes; mDevice->NumUpdates = 2; @@ -218,7 +218,6 @@ int JackPlayback::bufferSizeNotify(jack_nframes_t numframes) ERR("Failed to reallocate ringbuffer\n"); aluHandleDisconnect(mDevice, "Failed to reallocate %u-sample buffer", bufsize); } - unlock(); return 0; } diff --git a/Alc/backends/opensl.cpp b/Alc/backends/opensl.cpp index 66bc6e8d..766b7675 100644 --- a/Alc/backends/opensl.cpp +++ b/Alc/backends/opensl.cpp @@ -839,9 +839,7 @@ ALCboolean OpenSLCapture::start() if(SL_RESULT_SUCCESS != result) { - lock(); aluHandleDisconnect(mDevice, "Failed to start capture: 0x%08x", result); - unlock(); return ALC_FALSE; } @@ -904,9 +902,7 @@ ALCenum OpenSLCapture::captureSamples(void* buffer, ALCuint samples) if(SL_RESULT_SUCCESS != result) { - lock(); aluHandleDisconnect(mDevice, "Failed to update capture buffer: 0x%08x", result); - unlock(); return ALC_INVALID_DEVICE; } diff --git a/Alc/backends/oss.cpp b/Alc/backends/oss.cpp index c18a1d86..b5640ae3 100644 --- a/Alc/backends/oss.cpp +++ b/Alc/backends/oss.cpp @@ -520,9 +520,7 @@ int OSScapture::recordProc() if(errno == EINTR || errno == EAGAIN) continue; ERR("poll failed: %s\n", strerror(errno)); - lock(); aluHandleDisconnect(mDevice, "Failed to check capture samples: %s", strerror(errno)); - unlock(); break; } else if(sret == 0) @@ -538,10 +536,8 @@ int OSScapture::recordProc() if(amt < 0) { ERR("read failed: %s\n", strerror(errno)); - lock(); aluHandleDisconnect(mDevice, "Failed reading capture samples: %s", strerror(errno)); - unlock(); break; } mRing->writeAdvance(amt/frame_size); diff --git a/Alc/backends/sndio.cpp b/Alc/backends/sndio.cpp index 5d74dd5a..c75eebee 100644 --- a/Alc/backends/sndio.cpp +++ b/Alc/backends/sndio.cpp @@ -94,9 +94,7 @@ int SndioPlayback::mixerProc() if(wrote == 0) { ERR("sio_write failed\n"); - lock(); aluHandleDisconnect(mDevice, "Failed to write playback samples"); - unlock(); break; } @@ -308,9 +306,7 @@ int SndioCapture::recordProc() size_t got{sio_read(mSndHandle, data.first.buf, minz(todo-total, data.first.len))}; if(!got) { - lock(); aluHandleDisconnect(mDevice, "Failed to read capture samples"); - unlock(); break; } diff --git a/Alc/backends/wasapi.cpp b/Alc/backends/wasapi.cpp index cb0b665b..d221565c 100644 --- a/Alc/backends/wasapi.cpp +++ b/Alc/backends/wasapi.cpp @@ -560,9 +560,7 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() if(FAILED(hr)) { ERR("CoInitializeEx(nullptr, COINIT_MULTITHREADED) failed: 0x%08lx\n", hr); - lock(); aluHandleDisconnect(mDevice, "COM init failed: 0x%08lx", hr); - unlock(); return 1; } @@ -578,9 +576,7 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() if(FAILED(hr)) { ERR("Failed to get padding: 0x%08lx\n", hr); - lock(); aluHandleDisconnect(mDevice, "Failed to retrieve buffer padding: 0x%08lx", hr); - unlock(); break; } mPadding.store(written, std::memory_order_relaxed); @@ -608,9 +604,7 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() if(FAILED(hr)) { ERR("Failed to buffer data: 0x%08lx\n", hr); - lock(); aluHandleDisconnect(mDevice, "Failed to send playback samples: 0x%08lx", hr); - unlock(); break; } } @@ -1194,9 +1188,7 @@ FORCE_ALIGN int WasapiCapture::recordProc() if(FAILED(hr)) { ERR("CoInitializeEx(nullptr, COINIT_MULTITHREADED) failed: 0x%08lx\n", hr); - lock(); aluHandleDisconnect(mDevice, "COM init failed: 0x%08lx", hr); - unlock(); return 1; } @@ -1268,9 +1260,7 @@ FORCE_ALIGN int WasapiCapture::recordProc() if(FAILED(hr)) { - lock(); aluHandleDisconnect(mDevice, "Failed to capture samples: 0x%08lx", hr); - unlock(); break; } diff --git a/Alc/backends/wave.cpp b/Alc/backends/wave.cpp index 49d4a735..36adce95 100644 --- a/Alc/backends/wave.cpp +++ b/Alc/backends/wave.cpp @@ -172,9 +172,7 @@ int WaveBackend::mixerProc() if(ferror(mFile)) { ERR("Error writing to file\n"); - lock(); aluHandleDisconnect(mDevice, "Failed to write playback samples"); - unlock(); break; } } diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index e23eb1fb..5e53a047 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -785,7 +785,11 @@ struct ALCdevice_struct { // Contexts created on this device std::atomic<ALCcontext*> ContextList{nullptr}; - std::mutex BackendLock; + /* This lock protects the device state (format, update size, etc) from + * being from being changed in multiple threads, or being accessed while + * being changed. It's also used to serialize calls to the backend. + */ + std::mutex StateLock; std::unique_ptr<BackendBase> Backend; std::atomic<ALCdevice*> next{nullptr}; diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 7a378562..4fcc4c9c 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -478,7 +478,7 @@ void ComputePanGains(const ALeffectslot *slot, const ALfloat*RESTRICT coeffs, AL ALboolean MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context, const ALsizei SamplesToDo); void aluMixData(ALCdevice *device, ALvoid *OutBuffer, ALsizei NumSamples); -/* Caller must lock the device, and the mixer must not be running. */ +/* Caller must lock the device state, and the mixer must not be running. */ void aluHandleDisconnect(ALCdevice *device, const char *msg, ...) DECL_FORMAT(printf, 2, 3); extern MixerFunc MixSamples; diff --git a/OpenAL32/alAuxEffectSlot.cpp b/OpenAL32/alAuxEffectSlot.cpp index 1b3b97be..fc43edbe 100644 --- a/OpenAL32/alAuxEffectSlot.cpp +++ b/OpenAL32/alAuxEffectSlot.cpp @@ -556,12 +556,12 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect FPUCtl mixer_mode{}; ALCdevice *Device{Context->Device}; - std::unique_lock<std::mutex> backlock{Device->BackendLock}; + std::unique_lock<std::mutex> statelock{Device->StateLock}; State->mOutBuffer = Device->Dry.Buffer; State->mOutChannels = Device->Dry.NumChannels; if(State->deviceUpdate(Device) == AL_FALSE) { - backlock.unlock(); + statelock.unlock(); mixer_mode.leave(); State->DecRef(); return AL_OUT_OF_MEMORY; diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp index 069d600b..a3428e02 100644 --- a/OpenAL32/alSource.cpp +++ b/OpenAL32/alSource.cpp @@ -1726,7 +1726,7 @@ ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL * clock time with the device latency. Order is important. */ values[0] = GetSourceSecOffset(Source, Context, &srcclock); - { std::lock_guard<std::mutex> _{device->BackendLock}; + { std::lock_guard<std::mutex> _{device->StateLock}; clocktime = GetClockLatency(device); } if(srcclock == clocktime.ClockTime) @@ -1989,7 +1989,7 @@ ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, * clock time with the device latency. Order is important. */ values[0] = GetSourceSampleOffset(Source, Context, &srcclock); - { std::lock_guard<std::mutex> _{device->BackendLock}; + { std::lock_guard<std::mutex> _{device->StateLock}; clocktime = GetClockLatency(device); } if(srcclock == clocktime.ClockTime) |