From 9b237790b274a9191e0835e84c28de6cefbc2d34 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 29 Mar 2020 23:57:37 -0700 Subject: Remove the mutex from the backend base --- alc/backends/alsa.cpp | 9 +++++---- alc/backends/base.h | 2 -- alc/backends/jack.cpp | 6 ++++-- alc/backends/opensl.cpp | 6 ++++-- alc/backends/wasapi.cpp | 6 ++++-- 5 files changed, 17 insertions(+), 12 deletions(-) (limited to 'alc') diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 3298f157..bfeec1b8 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -425,6 +425,8 @@ struct AlsaPlayback final : public BackendBase { snd_pcm_t *mPcmHandle{nullptr}; + std::mutex mMutex; + al::vector mBuffer; std::atomic mKillNow{true}; @@ -493,7 +495,7 @@ int AlsaPlayback::mixerProc() avail -= avail%update_size; // it is possible that contiguous areas are smaller, thus we use a loop - std::lock_guard _{mMutex}; + std::lock_guard _{mMutex}; while(avail > 0) { snd_pcm_uframes_t frames{avail}; @@ -575,7 +577,7 @@ int AlsaPlayback::mixerNoMMapProc() al::byte *WritePtr{mBuffer.data()}; avail = snd_pcm_bytes_to_frames(mPcmHandle, static_cast(mBuffer.size())); - std::lock_guard _{mMutex}; + std::lock_guard _{mMutex}; aluMixData(mDevice, WritePtr, static_cast(avail), frame_step); while(avail > 0) { @@ -848,7 +850,7 @@ ClockLatency AlsaPlayback::getClockLatency() { ClockLatency ret; - std::lock_guard _{mMutex}; + std::lock_guard _{mMutex}; ret.ClockTime = GetDeviceClockTime(mDevice); snd_pcm_sframes_t delay{}; int err{snd_pcm_delay(mPcmHandle, &delay)}; @@ -1168,7 +1170,6 @@ ClockLatency AlsaCapture::getClockLatency() { ClockLatency ret; - std::lock_guard _{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 6887a813..310191b1 100644 --- a/alc/backends/base.h +++ b/alc/backends/base.h @@ -45,8 +45,6 @@ struct BackendBase { ALCdevice *mDevice; - std::recursive_mutex mMutex; - BackendBase(ALCdevice *device) noexcept; virtual ~BackendBase(); }; diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index 7e91f28c..0cad064d 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -169,6 +169,8 @@ struct JackPlayback final : public BackendBase { jack_client_t *mClient{nullptr}; jack_port_t *mPort[MAX_OUTPUT_CHANNELS]{}; + std::mutex mMutex; + std::atomic mPlaying{false}; RingBufferPtr mRing; al::semaphore mSem; @@ -282,7 +284,7 @@ int JackPlayback::mixerProc() ALuint len1{minu(static_cast(data.first.len), todo)}; ALuint len2{minu(static_cast(data.second.len), todo-len1)}; - std::lock_guard _{mMutex}; + std::lock_guard _{mMutex}; aluMixData(mDevice, data.first.buf, len1, frame_step); if(len2 > 0) aluMixData(mDevice, data.second.buf, len2, frame_step); @@ -458,7 +460,7 @@ ClockLatency JackPlayback::getClockLatency() { ClockLatency ret; - std::lock_guard _{mMutex}; + std::lock_guard _{mMutex}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mRing->readSpace()}; ret.Latency /= mDevice->Frequency; diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 635d6c0d..b1355061 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -171,6 +171,8 @@ struct OpenSLPlayback final : public BackendBase { RingBufferPtr mRing{nullptr}; al::semaphore mSem; + std::mutex mMutex; + ALuint mFrameSize{0}; std::atomic mKillNow{true}; @@ -260,7 +262,7 @@ int OpenSLPlayback::mixerProc() } } - std::unique_lock dlock{mMutex}; + std::unique_lock dlock{mMutex}; auto data = mRing->getWriteVector(); aluMixData(mDevice, data.first.buf, static_cast(data.first.len*mDevice->UpdateSize), frame_step); @@ -610,7 +612,7 @@ ClockLatency OpenSLPlayback::getClockLatency() { ClockLatency ret; - std::lock_guard _{mMutex}; + std::lock_guard _{mMutex}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mRing->readSpace() * mDevice->UpdateSize}; ret.Latency /= mDevice->Frequency; diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 0f58d426..fc48d492 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -658,6 +658,8 @@ struct WasapiPlayback final : public BackendBase, WasapiProxy { UINT32 mFrameStep{0u}; std::atomic mPadding{0u}; + std::mutex mMutex; + std::atomic mKillNow{true}; std::thread mThread; @@ -717,7 +719,7 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() if(SUCCEEDED(hr)) { { - std::lock_guard _{mMutex}; + std::lock_guard _{mMutex}; aluMixData(mDevice, buffer, len, mFrameStep); mPadding.store(written + len, std::memory_order_relaxed); } @@ -1167,7 +1169,7 @@ ClockLatency WasapiPlayback::getClockLatency() { ClockLatency ret; - std::lock_guard _{mMutex}; + std::lock_guard _{mMutex}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mPadding.load(std::memory_order_relaxed)}; ret.Latency /= mDevice->Frequency; -- cgit v1.2.3