summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorOleg Kosenkov <oleg@kosenkov.ca>2022-10-30 02:34:38 -0400
committerAndreas Kling <kling@serenityos.org>2022-10-31 00:00:52 +0100
commit0c27d95e760d2a30b287f913a4d238c7af63c724 (patch)
treeb69d349939da595643d497ee9b2cba63ad4ff6ad /Userland/Services
parent466000e05f9d908b609ccf84c7c431066ae25d12 (diff)
downloadserenity-0c27d95e760d2a30b287f913a4d238c7af63c724.zip
Userland: Use Threading::MutexLocker to lock/unlock mutexes
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/AudioServer/Mixer.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/Userland/Services/AudioServer/Mixer.cpp b/Userland/Services/AudioServer/Mixer.cpp
index 9e8cf14d8b..4b5cdc41be 100644
--- a/Userland/Services/AudioServer/Mixer.cpp
+++ b/Userland/Services/AudioServer/Mixer.cpp
@@ -45,11 +45,10 @@ Mixer::Mixer(NonnullRefPtr<Core::ConfigFile> config)
NonnullRefPtr<ClientAudioStream> Mixer::create_queue(ConnectionFromClient& client)
{
auto queue = adopt_ref(*new ClientAudioStream(client));
- m_pending_mutex.lock();
-
- m_pending_mixing.append(*queue);
-
- m_pending_mutex.unlock();
+ {
+ Threading::MutexLocker const locker(m_pending_mutex);
+ m_pending_mixing.append(*queue);
+ }
// Signal the mixer thread to start back up, in case nobody was connected before.
m_mixing_necessary.signal();
@@ -61,14 +60,15 @@ void Mixer::mix()
decltype(m_pending_mixing) active_mix_queues;
for (;;) {
- m_pending_mutex.lock();
- // While we have nothing to mix, wait on the condition.
- m_mixing_necessary.wait_while([this, &active_mix_queues]() { return m_pending_mixing.is_empty() && active_mix_queues.is_empty(); });
- if (!m_pending_mixing.is_empty()) {
- active_mix_queues.extend(move(m_pending_mixing));
- m_pending_mixing.clear();
+ {
+ Threading::MutexLocker const locker(m_pending_mutex);
+ // While we have nothing to mix, wait on the condition.
+ m_mixing_necessary.wait_while([this, &active_mix_queues]() { return m_pending_mixing.is_empty() && active_mix_queues.is_empty(); });
+ if (!m_pending_mixing.is_empty()) {
+ active_mix_queues.extend(move(m_pending_mixing));
+ m_pending_mixing.clear();
+ }
}
- m_pending_mutex.unlock();
active_mix_queues.remove_all_matching([&](auto& entry) { return !entry->client(); });