diff options
author | Chris Robinson <[email protected]> | 2019-10-07 23:22:06 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-10-07 23:22:06 -0700 |
commit | 52a003e9bb7c870f26436b38e62edc96385805dc (patch) | |
tree | 7625ddfd05dc06c62f8870c2f24cd22bdf5ddd68 | |
parent | f0fa6c6baf673a35337d2f2cb5548dd1e33c11e7 (diff) |
Avoid raw lock/unlock calls
-rw-r--r-- | alc/backends/alsa.cpp | 12 | ||||
-rw-r--r-- | alc/backends/coreaudio.cpp | 3 | ||||
-rw-r--r-- | alc/backends/dsound.cpp | 5 | ||||
-rw-r--r-- | alc/backends/jack.cpp | 10 | ||||
-rw-r--r-- | alc/backends/null.cpp | 3 | ||||
-rw-r--r-- | alc/backends/opensl.cpp | 10 | ||||
-rw-r--r-- | alc/backends/oss.cpp | 7 | ||||
-rw-r--r-- | alc/backends/portaudio.cpp | 3 | ||||
-rw-r--r-- | alc/backends/qsa.cpp | 7 | ||||
-rw-r--r-- | alc/backends/sndio.cpp | 7 | ||||
-rw-r--r-- | alc/backends/solaris.cpp | 7 | ||||
-rw-r--r-- | alc/backends/wasapi.cpp | 7 | ||||
-rw-r--r-- | alc/backends/wave.cpp | 7 | ||||
-rw-r--r-- | alc/backends/winmm.cpp | 14 |
14 files changed, 44 insertions, 58 deletions
diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 2e157602..a9eb6d5f 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -471,7 +471,7 @@ int AlsaPlayback::mixerProc() avail -= avail%update_size; // it is possible that contiguous areas are smaller, thus we use a loop - lock(); + std::lock_guard<AlsaPlayback> _{*this}; while(avail > 0) { snd_pcm_uframes_t frames{avail}; @@ -498,7 +498,6 @@ int AlsaPlayback::mixerProc() avail -= frames; } - unlock(); } return 0; @@ -551,7 +550,7 @@ int AlsaPlayback::mixerNoMMapProc() continue; } - lock(); + std::lock_guard<AlsaPlayback> _{*this}; al::byte *WritePtr{mBuffer.data()}; avail = snd_pcm_bytes_to_frames(mPcmHandle, static_cast<ssize_t>(mBuffer.size())); aluMixData(mDevice, WritePtr, static_cast<ALuint>(avail)); @@ -586,7 +585,6 @@ int AlsaPlayback::mixerNoMMapProc() if(ret < 0) break; } } - unlock(); } return 0; @@ -847,7 +845,7 @@ ClockLatency AlsaPlayback::getClockLatency() { ClockLatency ret; - lock(); + std::lock_guard<AlsaPlayback> _{*this}; ret.ClockTime = GetDeviceClockTime(mDevice); snd_pcm_sframes_t delay{}; int err{snd_pcm_delay(mPcmHandle, &delay)}; @@ -858,7 +856,6 @@ ClockLatency AlsaPlayback::getClockLatency() } ret.Latency = std::chrono::seconds{std::max<snd_pcm_sframes_t>(0, delay)}; ret.Latency /= mDevice->Frequency; - unlock(); return ret; } @@ -1188,7 +1185,7 @@ ClockLatency AlsaCapture::getClockLatency() { ClockLatency ret; - lock(); + std::lock_guard<AlsaCapture> _{*this}; ret.ClockTime = GetDeviceClockTime(mDevice); snd_pcm_sframes_t delay{}; int err{snd_pcm_delay(mPcmHandle, &delay)}; @@ -1199,7 +1196,6 @@ ClockLatency AlsaCapture::getClockLatency() } ret.Latency = std::chrono::seconds{std::max<snd_pcm_sframes_t>(0, delay)}; ret.Latency /= mDevice->Frequency; - unlock(); return ret; } diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 9254dbe0..3a97c105 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -81,9 +81,8 @@ CoreAudioPlayback::~CoreAudioPlayback() OSStatus CoreAudioPlayback::MixerProc(AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32, UInt32, AudioBufferList *ioData) { - lock(); + std::lock_guard<CoreAudioPlayback> _{*this}; aluMixData(mDevice, ioData->mBuffers[0].mData, ioData->mBuffers[0].mDataByteSize/mFrameSize); - unlock(); return noErr; } diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 19a3c604..d48b74e2 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -276,17 +276,18 @@ FORCE_ALIGN int DSoundPlayback::mixerProc() if(SUCCEEDED(err)) { - lock(); + std::unique_lock<DSoundPlayback> dlock{*this}; aluMixData(mDevice, WritePtr1, WriteCnt1/FrameSize); if(WriteCnt2 > 0) aluMixData(mDevice, WritePtr2, WriteCnt2/FrameSize); - unlock(); + 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 c7e2839c..7c3f1822 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -296,15 +296,15 @@ int JackPlayback::mixerProc() SetRTPriority(); althrd_setname(MIXER_THREAD_NAME); - lock(); + 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) { - unlock(); + dlock.unlock(); mSem.wait(); - lock(); + dlock.lock(); continue; } @@ -320,7 +320,6 @@ int JackPlayback::mixerProc() aluMixData(mDevice, data.second.buf, len2); mRing->writeAdvance(todo); } - unlock(); return 0; } @@ -484,11 +483,10 @@ ClockLatency JackPlayback::getClockLatency() { ClockLatency ret; - lock(); + std::lock_guard<JackPlayback> _{*this}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mRing->readSpace()}; ret.Latency /= mDevice->Frequency; - unlock(); return ret; } diff --git a/alc/backends/null.cpp b/alc/backends/null.cpp index aca59605..bc2a0c9c 100644 --- a/alc/backends/null.cpp +++ b/alc/backends/null.cpp @@ -86,9 +86,8 @@ int NullBackend::mixerProc() } while(avail-done >= mDevice->UpdateSize) { - lock(); + std::lock_guard<NullBackend> _{*this}; aluMixData(mDevice, nullptr, mDevice->UpdateSize); - unlock(); done += mDevice->UpdateSize; } diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 4e4ceb5b..f546f168 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -228,7 +228,7 @@ int OpenSLPlayback::mixerProc() PRINTERR(result, "bufferQueue->GetInterface SL_IID_PLAY"); } - lock(); + std::unique_lock<OpenSLPlayback> dlock{*this}; if(SL_RESULT_SUCCESS != result) aluHandleDisconnect(mDevice, "Failed to get playback buffer: 0x%08x", result); @@ -254,9 +254,9 @@ int OpenSLPlayback::mixerProc() if(mRing->writeSpace() == 0) { - unlock(); + dlock.unlock(); mSem.wait(); - lock(); + dlock.lock(); continue; } } @@ -292,7 +292,6 @@ int OpenSLPlayback::mixerProc() data.first.buf += mDevice->UpdateSize*mFrameSize; } } - unlock(); return 0; } @@ -617,11 +616,10 @@ ClockLatency OpenSLPlayback::getClockLatency() { ClockLatency ret; - lock(); + std::lock_guard<OpenSLPlayback> _{*this}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mRing->readSpace() * mDevice->UpdateSize}; ret.Latency /= mDevice->Frequency; - unlock(); return ret; } diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 1e3ad28b..5ab07dbe 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -279,7 +279,7 @@ int OSSPlayback::mixerProc() const ALuint frame_size{mDevice->frameSizeFromFmt()}; - lock(); + std::unique_lock<OSSPlayback> dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { @@ -287,9 +287,9 @@ int OSSPlayback::mixerProc() pollitem.fd = mFd; pollitem.events = POLLOUT; - unlock(); + dlock.unlock(); int pret{poll(&pollitem, 1, 1000)}; - lock(); + dlock.lock(); if(pret < 0) { if(errno == EINTR || errno == EAGAIN) @@ -324,7 +324,6 @@ int OSSPlayback::mixerProc() write_ptr += wrote; } } - unlock(); return 0; } diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 7847f41d..ba8e4984 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -110,9 +110,8 @@ int PortPlayback::writeCallback(const void*, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo*, const PaStreamCallbackFlags) { - lock(); + std::lock_guard<PortPlayback> _{*this}; aluMixData(mDevice, outputBuffer, static_cast<ALuint>(framesPerBuffer)); - unlock(); return 0; } diff --git a/alc/backends/qsa.cpp b/alc/backends/qsa.cpp index 872a8541..5ed65798 100644 --- a/alc/backends/qsa.cpp +++ b/alc/backends/qsa.cpp @@ -207,7 +207,7 @@ FORCE_ALIGN static int qsa_proc_playback(void *ptr) const ALint frame_size = device->frameSizeFromFmt(); - self->lock(); + std::unique_lock<PlaybackWrapper> dlock{*self}; while(!data->mKillNow.load(std::memory_order_acquire)) { pollfd pollitem{}; @@ -215,9 +215,9 @@ FORCE_ALIGN static int qsa_proc_playback(void *ptr) pollitem.events = POLLOUT; /* Select also works like time slice to OS */ - self->unlock(); + dlock.unlock(); sret = poll(&pollitem, 1, 2000); - self->lock(); + dlock.lock(); if(sret == -1) { if(errno == EINTR || errno == EAGAIN) @@ -266,7 +266,6 @@ FORCE_ALIGN static int qsa_proc_playback(void *ptr) } } } - self->unlock(); return 0; } diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index e0c70762..5657a241 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -85,9 +85,10 @@ int SndioPlayback::mixerProc() ALubyte *WritePtr{mBuffer.data()}; size_t len{mBuffer.size()}; - lock(); - aluMixData(mDevice, WritePtr, static_cast<ALuint>(len/frameSize)); - unlock(); + { + std::lock_guard<SndioPlayback> _{*this}; + aluMixData(mDevice, WritePtr, static_cast<ALuint>(len/frameSize)); + } 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 5963a4b2..79cc224d 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -91,7 +91,7 @@ int SolarisBackend::mixerProc() const ALuint frame_size{mDevice->frameSizeFromFmt()}; - lock(); + std::unique_lock<SolarisBackend> dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { @@ -99,9 +99,9 @@ int SolarisBackend::mixerProc() pollitem.fd = mFd; pollitem.events = POLLOUT; - unlock(); + dlock.unlock(); int pret{poll(&pollitem, 1, 1000)}; - lock(); + dlock.lock(); if(pret < 0) { if(errno == EINTR || errno == EAGAIN) @@ -137,7 +137,6 @@ int SolarisBackend::mixerProc() write_ptr += wrote; } } - unlock(); return 0; } diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index b6f5b5fb..181518d0 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -689,10 +689,10 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() hr = mRender->GetBuffer(len, &buffer); if(SUCCEEDED(hr)) { - lock(); + std::unique_lock<WasapiPlayback> dlock{*this}; aluMixData(mDevice, buffer, len); mPadding.store(written + len, std::memory_order_relaxed); - unlock(); + dlock.unlock(); hr = mRender->ReleaseBuffer(len, 0); } if(FAILED(hr)) @@ -1136,11 +1136,10 @@ ClockLatency WasapiPlayback::getClockLatency() { ClockLatency ret; - lock(); + std::lock_guard<WasapiPlayback> _{*this}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mPadding.load(std::memory_order_relaxed)}; ret.Latency /= mDevice->Frequency; - unlock(); return ret; } diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 927cb276..3b0a30d8 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -145,9 +145,10 @@ int WaveBackend::mixerProc() } while(avail-done >= mDevice->UpdateSize) { - lock(); - aluMixData(mDevice, mBuffer.data(), mDevice->UpdateSize); - unlock(); + { + std::lock_guard<WaveBackend> _{*this}; + aluMixData(mDevice, mBuffer.data(), mDevice->UpdateSize); + } done += mDevice->UpdateSize; if(!IS_LITTLE_ENDIAN) diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index c287e136..8f85f351 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -183,16 +183,16 @@ FORCE_ALIGN int WinMMPlayback::mixerProc() SetRTPriority(); althrd_setname(MIXER_THREAD_NAME); - lock(); + 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) { - unlock(); + dlock.unlock(); mSem.wait(); - lock(); + dlock.lock(); continue; } @@ -207,7 +207,6 @@ FORCE_ALIGN int WinMMPlayback::mixerProc() } while(--todo); mIdx = static_cast<ALuint>(widx); } - unlock(); return 0; } @@ -427,16 +426,16 @@ int WinMMCapture::captureProc() { althrd_setname(RECORD_THREAD_NAME); - lock(); + 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) { - unlock(); + dlock.unlock(); mSem.wait(); - lock(); + dlock.lock(); continue; } @@ -451,7 +450,6 @@ int WinMMCapture::captureProc() } while(--todo); mIdx = static_cast<ALuint>(widx); } - unlock(); return 0; } |