mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:37:45 +00:00
Userland: Use Threading::MutexLocker to lock/unlock mutexes
This commit is contained in:
parent
466000e05f
commit
0c27d95e76
3 changed files with 15 additions and 20 deletions
|
@ -59,10 +59,8 @@ ErrorOr<void> ImageProcessor::enqueue_command(NonnullRefPtr<ImageProcessingComma
|
||||||
m_processor_thread->detach();
|
m_processor_thread->detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_wakeup_mutex.lock();
|
Threading::MutexLocker const locker(m_wakeup_mutex);
|
||||||
m_wakeup_variable.signal();
|
m_wakeup_variable.signal();
|
||||||
m_wakeup_mutex.unlock();
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,8 @@ ConnectionToServer::ConnectionToServer(NonnullOwnPtr<Core::Stream::LocalSocket>
|
||||||
Core::EventLoop enqueuer_loop;
|
Core::EventLoop enqueuer_loop;
|
||||||
m_enqueuer_loop = &enqueuer_loop;
|
m_enqueuer_loop = &enqueuer_loop;
|
||||||
enqueuer_loop.exec();
|
enqueuer_loop.exec();
|
||||||
m_enqueuer_loop_destruction.lock();
|
Threading::MutexLocker const locker(m_enqueuer_loop_destruction);
|
||||||
m_enqueuer_loop = nullptr;
|
m_enqueuer_loop = nullptr;
|
||||||
m_enqueuer_loop_destruction.unlock();
|
|
||||||
return (intptr_t) nullptr;
|
return (intptr_t) nullptr;
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
|
@ -45,12 +44,10 @@ ConnectionToServer::~ConnectionToServer()
|
||||||
void ConnectionToServer::die()
|
void ConnectionToServer::die()
|
||||||
{
|
{
|
||||||
// We're sometimes getting here after the other thread has already exited and its event loop does no longer exist.
|
// We're sometimes getting here after the other thread has already exited and its event loop does no longer exist.
|
||||||
m_enqueuer_loop_destruction.lock();
|
if (Threading::MutexLocker const locker(m_enqueuer_loop_destruction); m_enqueuer_loop != nullptr) {
|
||||||
if (m_enqueuer_loop != nullptr) {
|
|
||||||
m_enqueuer_loop->wake();
|
m_enqueuer_loop->wake();
|
||||||
m_enqueuer_loop->quit(0);
|
m_enqueuer_loop->quit(0);
|
||||||
}
|
}
|
||||||
m_enqueuer_loop_destruction.unlock();
|
|
||||||
(void)m_background_audio_enqueuer->join();
|
(void)m_background_audio_enqueuer->join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,10 @@ Mixer::Mixer(NonnullRefPtr<Core::ConfigFile> config)
|
||||||
NonnullRefPtr<ClientAudioStream> Mixer::create_queue(ConnectionFromClient& client)
|
NonnullRefPtr<ClientAudioStream> Mixer::create_queue(ConnectionFromClient& client)
|
||||||
{
|
{
|
||||||
auto queue = adopt_ref(*new ClientAudioStream(client));
|
auto queue = adopt_ref(*new ClientAudioStream(client));
|
||||||
m_pending_mutex.lock();
|
{
|
||||||
|
Threading::MutexLocker const locker(m_pending_mutex);
|
||||||
m_pending_mixing.append(*queue);
|
m_pending_mixing.append(*queue);
|
||||||
|
}
|
||||||
m_pending_mutex.unlock();
|
|
||||||
// Signal the mixer thread to start back up, in case nobody was connected before.
|
// Signal the mixer thread to start back up, in case nobody was connected before.
|
||||||
m_mixing_necessary.signal();
|
m_mixing_necessary.signal();
|
||||||
|
|
||||||
|
@ -61,14 +60,15 @@ void Mixer::mix()
|
||||||
decltype(m_pending_mixing) active_mix_queues;
|
decltype(m_pending_mixing) active_mix_queues;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
m_pending_mutex.lock();
|
{
|
||||||
// While we have nothing to mix, wait on the condition.
|
Threading::MutexLocker const locker(m_pending_mutex);
|
||||||
m_mixing_necessary.wait_while([this, &active_mix_queues]() { return m_pending_mixing.is_empty() && active_mix_queues.is_empty(); });
|
// While we have nothing to mix, wait on the condition.
|
||||||
if (!m_pending_mixing.is_empty()) {
|
m_mixing_necessary.wait_while([this, &active_mix_queues]() { return m_pending_mixing.is_empty() && active_mix_queues.is_empty(); });
|
||||||
active_mix_queues.extend(move(m_pending_mixing));
|
if (!m_pending_mixing.is_empty()) {
|
||||||
m_pending_mixing.clear();
|
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(); });
|
active_mix_queues.remove_all_matching([&](auto& entry) { return !entry->client(); });
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue