mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
Userland: Use Threading::MutexLocker to lock/unlock mutexes
This commit is contained in:
parent
466000e05f
commit
0c27d95e76
Notes:
sideshowbarker
2024-07-17 10:05:47 +09:00
Author: https://github.com/idispatch 🔰 Commit: https://github.com/SerenityOS/serenity/commit/0c27d95e76 Pull-request: https://github.com/SerenityOS/serenity/pull/15854 Reviewed-by: https://github.com/awesomekling
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_wakeup_mutex.lock();
|
||||
Threading::MutexLocker const locker(m_wakeup_mutex);
|
||||
m_wakeup_variable.signal();
|
||||
m_wakeup_mutex.unlock();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -27,9 +27,8 @@ ConnectionToServer::ConnectionToServer(NonnullOwnPtr<Core::Stream::LocalSocket>
|
|||
Core::EventLoop enqueuer_loop;
|
||||
m_enqueuer_loop = &enqueuer_loop;
|
||||
enqueuer_loop.exec();
|
||||
m_enqueuer_loop_destruction.lock();
|
||||
Threading::MutexLocker const locker(m_enqueuer_loop_destruction);
|
||||
m_enqueuer_loop = nullptr;
|
||||
m_enqueuer_loop_destruction.unlock();
|
||||
return (intptr_t) nullptr;
|
||||
}))
|
||||
{
|
||||
|
@ -45,12 +44,10 @@ ConnectionToServer::~ConnectionToServer()
|
|||
void ConnectionToServer::die()
|
||||
{
|
||||
// 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 (m_enqueuer_loop != nullptr) {
|
||||
if (Threading::MutexLocker const locker(m_enqueuer_loop_destruction); m_enqueuer_loop != nullptr) {
|
||||
m_enqueuer_loop->wake();
|
||||
m_enqueuer_loop->quit(0);
|
||||
}
|
||||
m_enqueuer_loop_destruction.unlock();
|
||||
(void)m_background_audio_enqueuer->join();
|
||||
}
|
||||
|
||||
|
|
|
@ -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(); });
|
||||
|
||||
|
|
Loading…
Reference in a new issue