diff options
-rw-r--r-- | alc/alc.cpp | 3 | ||||
-rw-r--r-- | alc/backends/alsa.cpp | 8 | ||||
-rw-r--r-- | alc/backends/base.h | 3 | ||||
-rw-r--r-- | alc/backends/coreaudio.cpp | 1 | ||||
-rw-r--r-- | alc/backends/dsound.cpp | 3 | ||||
-rw-r--r-- | alc/backends/jack.cpp | 6 | ||||
-rw-r--r-- | alc/backends/null.cpp | 1 | ||||
-rw-r--r-- | alc/backends/opensl.cpp | 7 | ||||
-rw-r--r-- | alc/backends/oss.cpp | 3 | ||||
-rw-r--r-- | alc/backends/portaudio.cpp | 1 | ||||
-rw-r--r-- | alc/backends/pulseaudio.cpp | 4 | ||||
-rw-r--r-- | alc/backends/qsa.cpp | 3 | ||||
-rw-r--r-- | alc/backends/sdl2.cpp | 8 | ||||
-rw-r--r-- | alc/backends/sndio.cpp | 5 | ||||
-rw-r--r-- | alc/backends/solaris.cpp | 3 | ||||
-rw-r--r-- | alc/backends/wasapi.cpp | 11 | ||||
-rw-r--r-- | alc/backends/wave.cpp | 5 | ||||
-rw-r--r-- | alc/backends/winmm.cpp | 6 |
18 files changed, 17 insertions, 64 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp index 3791c7fd..59739e04 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -4233,10 +4233,7 @@ START_API_FUNC else if(samples < 0 || (samples > 0 && buffer == nullptr)) alcSetError(dev.get(), ALC_INVALID_VALUE); else - { - std::lock_guard<BackendBase> _{*dev->Backend}; aluMixData(dev.get(), buffer, static_cast<ALuint>(samples), dev->channelsFromFmt()); - } } END_API_FUNC diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index a011d720..3298f157 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -493,7 +493,7 @@ int AlsaPlayback::mixerProc() avail -= avail%update_size; // it is possible that contiguous areas are smaller, thus we use a loop - std::lock_guard<AlsaPlayback> _{*this}; + std::lock_guard<std::recursive_mutex> _{mMutex}; while(avail > 0) { snd_pcm_uframes_t frames{avail}; @@ -573,9 +573,9 @@ int AlsaPlayback::mixerNoMMapProc() continue; } - std::lock_guard<AlsaPlayback> _{*this}; al::byte *WritePtr{mBuffer.data()}; avail = snd_pcm_bytes_to_frames(mPcmHandle, static_cast<ssize_t>(mBuffer.size())); + std::lock_guard<std::recursive_mutex> _{mMutex}; aluMixData(mDevice, WritePtr, static_cast<ALuint>(avail), frame_step); while(avail > 0) { @@ -848,7 +848,7 @@ ClockLatency AlsaPlayback::getClockLatency() { ClockLatency ret; - std::lock_guard<AlsaPlayback> _{*this}; + std::lock_guard<std::recursive_mutex> _{mMutex}; ret.ClockTime = GetDeviceClockTime(mDevice); snd_pcm_sframes_t delay{}; int err{snd_pcm_delay(mPcmHandle, &delay)}; @@ -1168,7 +1168,7 @@ ClockLatency AlsaCapture::getClockLatency() { ClockLatency ret; - std::lock_guard<AlsaCapture> _{*this}; + std::lock_guard<std::recursive_mutex> _{mMutex}; ret.ClockTime = GetDeviceClockTime(mDevice); snd_pcm_sframes_t delay{}; int err{snd_pcm_delay(mPcmHandle, &delay)}; diff --git a/alc/backends/base.h b/alc/backends/base.h index 3942a673..6887a813 100644 --- a/alc/backends/base.h +++ b/alc/backends/base.h @@ -43,9 +43,6 @@ struct BackendBase { virtual ClockLatency getClockLatency(); - virtual void lock() { mMutex.lock(); } - virtual void unlock() { mMutex.unlock(); } - ALCdevice *mDevice; std::recursive_mutex mMutex; diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 9948d11c..5570b716 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -81,7 +81,6 @@ CoreAudioPlayback::~CoreAudioPlayback() OSStatus CoreAudioPlayback::MixerProc(AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32, UInt32, AudioBufferList *ioData) noexcept { - std::lock_guard<CoreAudioPlayback> _{*this}; aluMixData(mDevice, ioData->mBuffers[0].mData, ioData->mBuffers[0].mDataByteSize/mFrameSize, ioData->mBuffers[0].mNumberChannels); return noErr; diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index cee5a20a..83b10116 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -276,18 +276,15 @@ FORCE_ALIGN int DSoundPlayback::mixerProc() if(SUCCEEDED(err)) { - std::unique_lock<DSoundPlayback> dlock{*this}; aluMixData(mDevice, WritePtr1, WriteCnt1/FrameSize, FrameStep); if(WriteCnt2 > 0) aluMixData(mDevice, WritePtr2, WriteCnt2/FrameSize, FrameStep); - dlock.unlock(); mBuffer->Unlock(WritePtr1, WriteCnt1, WritePtr2, WriteCnt2); } else { ERR("Buffer lock error: %#lx\n", err); - std::lock_guard<DSoundPlayback> _{*this}; aluHandleDisconnect(mDevice, "Failed to lock output buffer: 0x%lx", err); return 1; } diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index 485225e4..97837460 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -266,15 +266,12 @@ int JackPlayback::mixerProc() const size_t frame_step{mDevice->channelsFromFmt()}; - std::unique_lock<JackPlayback> dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { if(mRing->writeSpace() < mDevice->UpdateSize) { - dlock.unlock(); mSem.wait(); - dlock.lock(); continue; } @@ -285,6 +282,7 @@ int JackPlayback::mixerProc() ALuint len1{minu(static_cast<ALuint>(data.first.len), todo)}; ALuint len2{minu(static_cast<ALuint>(data.second.len), todo-len1)}; + std::lock_guard<std::recursive_mutex> _{mMutex}; aluMixData(mDevice, data.first.buf, len1, frame_step); if(len2 > 0) aluMixData(mDevice, data.second.buf, len2, frame_step); @@ -460,7 +458,7 @@ ClockLatency JackPlayback::getClockLatency() { ClockLatency ret; - std::lock_guard<JackPlayback> _{*this}; + std::lock_guard<std::recursive_mutex> _{mMutex}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mRing->readSpace()}; ret.Latency /= mDevice->Frequency; diff --git a/alc/backends/null.cpp b/alc/backends/null.cpp index 9f069be8..4cdebf57 100644 --- a/alc/backends/null.cpp +++ b/alc/backends/null.cpp @@ -86,7 +86,6 @@ int NullBackend::mixerProc() } while(avail-done >= mDevice->UpdateSize) { - std::lock_guard<NullBackend> _{*this}; aluMixData(mDevice, nullptr, mDevice->UpdateSize, 0u); done += mDevice->UpdateSize; } diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index aafba2c8..635d6c0d 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -230,7 +230,6 @@ int OpenSLPlayback::mixerProc() const size_t frame_step{mDevice->channelsFromFmt()}; - std::unique_lock<OpenSLPlayback> dlock{*this}; if(SL_RESULT_SUCCESS != result) aluHandleDisconnect(mDevice, "Failed to get playback buffer: 0x%08x", result); @@ -256,13 +255,12 @@ int OpenSLPlayback::mixerProc() if(mRing->writeSpace() == 0) { - dlock.unlock(); mSem.wait(); - dlock.lock(); continue; } } + std::unique_lock<std::recursive_mutex> dlock{mMutex}; auto data = mRing->getWriteVector(); aluMixData(mDevice, data.first.buf, static_cast<ALuint>(data.first.len*mDevice->UpdateSize), frame_step); @@ -272,6 +270,7 @@ int OpenSLPlayback::mixerProc() size_t todo{data.first.len + data.second.len}; mRing->writeAdvance(todo); + dlock.unlock(); for(size_t i{0};i < todo;i++) { @@ -611,7 +610,7 @@ ClockLatency OpenSLPlayback::getClockLatency() { ClockLatency ret; - std::lock_guard<OpenSLPlayback> _{*this}; + std::lock_guard<std::recursive_mutex> _{mMutex}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mRing->readSpace() * mDevice->UpdateSize}; ret.Latency /= mDevice->Frequency; diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 74bdbb11..ad1df7d6 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -280,7 +280,6 @@ int OSSPlayback::mixerProc() const size_t frame_step{mDevice->channelsFromFmt()}; const ALuint frame_size{mDevice->frameSizeFromFmt()}; - std::unique_lock<OSSPlayback> dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { @@ -288,9 +287,7 @@ int OSSPlayback::mixerProc() pollitem.fd = mFd; pollitem.events = POLLOUT; - dlock.unlock(); int pret{poll(&pollitem, 1, 1000)}; - dlock.lock(); if(pret < 0) { if(errno == EINTR || errno == EAGAIN) diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 0f5d6d6d..96eb1af4 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -109,7 +109,6 @@ PortPlayback::~PortPlayback() int PortPlayback::writeCallback(const void*, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo*, const PaStreamCallbackFlags) noexcept { - std::lock_guard<PortPlayback> _{*this}; aluMixData(mDevice, outputBuffer, static_cast<ALuint>(framesPerBuffer), mDevice->channelsFromFmt()); return 0; diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index be4e742c..dcce8e85 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -710,8 +710,6 @@ struct PulsePlayback final : public BackendBase { bool start() override; void stop() override; ClockLatency getClockLatency() override; - void lock() override { mMainloop.doLock(); } - void unlock() override { mMainloop.doUnlock(); } PulseMainloop mMainloop; @@ -1107,8 +1105,6 @@ struct PulseCapture final : public BackendBase { ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; ClockLatency getClockLatency() override; - void lock() override { mMainloop.doLock(); } - void unlock() override { mMainloop.doUnlock(); } PulseMainloop mMainloop; diff --git a/alc/backends/qsa.cpp b/alc/backends/qsa.cpp index 5ed65798..ef43e080 100644 --- a/alc/backends/qsa.cpp +++ b/alc/backends/qsa.cpp @@ -207,7 +207,6 @@ FORCE_ALIGN static int qsa_proc_playback(void *ptr) const ALint frame_size = device->frameSizeFromFmt(); - std::unique_lock<PlaybackWrapper> dlock{*self}; while(!data->mKillNow.load(std::memory_order_acquire)) { pollfd pollitem{}; @@ -215,9 +214,7 @@ FORCE_ALIGN static int qsa_proc_playback(void *ptr) pollitem.events = POLLOUT; /* Select also works like time slice to OS */ - dlock.unlock(); sret = poll(&pollitem, 1, 2000); - dlock.lock(); if(sret == -1) { if(errno == EINTR || errno == EAGAIN) diff --git a/alc/backends/sdl2.cpp b/alc/backends/sdl2.cpp index abb240e4..af3081f1 100644 --- a/alc/backends/sdl2.cpp +++ b/alc/backends/sdl2.cpp @@ -60,8 +60,6 @@ struct Sdl2Backend final : public BackendBase { bool reset() override; bool start() override; void stop() override; - void lock() override; - void unlock() override; SDL_AudioDeviceID mDeviceID{0u}; ALuint mFrameSize{0}; @@ -181,12 +179,6 @@ bool Sdl2Backend::start() void Sdl2Backend::stop() { SDL_PauseAudioDevice(mDeviceID, 1); } -void Sdl2Backend::lock() -{ SDL_LockAudioDevice(mDeviceID); } - -void Sdl2Backend::unlock() -{ SDL_UnlockAudioDevice(mDeviceID); } - } // namespace BackendFactory &SDL2BackendFactory::getFactory() diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 0ca7062d..5b95a8f0 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -86,10 +86,7 @@ int SndioPlayback::mixerProc() ALubyte *WritePtr{mBuffer.data()}; size_t len{mBuffer.size()}; - { - std::lock_guard<SndioPlayback> _{*this}; - aluMixData(mDevice, WritePtr, static_cast<ALuint>(len/frameSize), frameStep); - } + aluMixData(mDevice, WritePtr, static_cast<ALuint>(len/frameSize), frameStep); while(len > 0 && !mKillNow.load(std::memory_order_acquire)) { size_t wrote{sio_write(mSndHandle, WritePtr, len)}; diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 6823777c..d292c012 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -92,7 +92,6 @@ int SolarisBackend::mixerProc() const size_t frame_step{mDevice->channelsFromFmt()}; const ALuint frame_size{mDevice->frameSizeFromFmt()}; - std::unique_lock<SolarisBackend> dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { @@ -100,9 +99,7 @@ int SolarisBackend::mixerProc() pollitem.fd = mFd; pollitem.events = POLLOUT; - dlock.unlock(); int pret{poll(&pollitem, 1, 1000)}; - dlock.lock(); if(pret < 0) { if(errno == EINTR || errno == EAGAIN) diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index f97c8636..4addad1d 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -715,10 +715,11 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() hr = mRender->GetBuffer(len, &buffer); if(SUCCEEDED(hr)) { - std::unique_lock<WasapiPlayback> dlock{*this}; - aluMixData(mDevice, buffer, len, mFrameStep); - mPadding.store(written + len, std::memory_order_relaxed); - dlock.unlock(); + { + std::lock_guard<std::recursive_mutex> _{mMutex}; + aluMixData(mDevice, buffer, len, mFrameStep); + mPadding.store(written + len, std::memory_order_relaxed); + } hr = mRender->ReleaseBuffer(len, 0); } if(FAILED(hr)) @@ -1164,7 +1165,7 @@ ClockLatency WasapiPlayback::getClockLatency() { ClockLatency ret; - std::lock_guard<WasapiPlayback> _{*this}; + std::lock_guard<std::recursive_mutex> _{mMutex}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mPadding.load(std::memory_order_relaxed)}; ret.Latency /= mDevice->Frequency; diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 4f357970..f4fa2b70 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -146,10 +146,7 @@ int WaveBackend::mixerProc() } while(avail-done >= mDevice->UpdateSize) { - { - std::lock_guard<WaveBackend> _{*this}; - aluMixData(mDevice, mBuffer.data(), mDevice->UpdateSize, frameStep); - } + aluMixData(mDevice, mBuffer.data(), mDevice->UpdateSize, frameStep); done += mDevice->UpdateSize; if(!IS_LITTLE_ENDIAN) diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index 53a58d0e..a2437496 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -182,16 +182,13 @@ FORCE_ALIGN int WinMMPlayback::mixerProc() const size_t frame_step{mDevice->channelsFromFmt()}; - std::unique_lock<WinMMPlayback> dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { ALsizei todo = mWritable.load(std::memory_order_acquire); if(todo < 1) { - dlock.unlock(); mSem.wait(); - dlock.lock(); continue; } @@ -422,16 +419,13 @@ int WinMMCapture::captureProc() { althrd_setname(RECORD_THREAD_NAME); - std::unique_lock<WinMMCapture> dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { ALuint todo{mReadable.load(std::memory_order_acquire)}; if(todo < 1) { - dlock.unlock(); mSem.wait(); - dlock.lock(); continue; } |