mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:57:44 +00:00
LibCore: Remove awkward EventLoop::wake_once() API
This was used in exactly one place, to avoid sending multiple CustomEvents to the enqueuer thread in Audio::ConnectionToServer. Instead of this, we now just send a CustomEvent and wake the enqueuer thread. If it wakes up and has multiple CustomEvents, they get delivered and ignored in no time anyway. Since they only get ignored if there's no work to be done, this seems harmless.
This commit is contained in:
parent
896d1e4f42
commit
9601b516b8
3 changed files with 7 additions and 31 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, kleines Filmröllchen <malu.bertsch@gmail.com>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
|
@ -518,30 +518,11 @@ size_t EventLoop::pump(WaitMode mode)
|
|||
return processed_events;
|
||||
}
|
||||
|
||||
void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event, ShouldWake should_wake)
|
||||
void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
|
||||
{
|
||||
Threading::MutexLocker lock(m_private->lock);
|
||||
dbgln_if(EVENTLOOP_DEBUG, "Core::EventLoop::post_event: ({}) << receiver={}, event={}", m_queued_events.size(), receiver, event);
|
||||
m_queued_events.empend(receiver, move(event));
|
||||
if (should_wake == ShouldWake::Yes)
|
||||
wake();
|
||||
}
|
||||
|
||||
void EventLoop::wake_once(Object& receiver, int custom_event_type)
|
||||
{
|
||||
Threading::MutexLocker lock(m_private->lock);
|
||||
dbgln_if(EVENTLOOP_DEBUG, "Core::EventLoop::wake_once: event type {}", custom_event_type);
|
||||
auto identical_events = m_queued_events.find_if([&](auto& queued_event) {
|
||||
if (queued_event.receiver.is_null())
|
||||
return false;
|
||||
auto const& event = queued_event.event;
|
||||
auto is_receiver_identical = queued_event.receiver.ptr() == &receiver;
|
||||
auto event_id_matches = event->type() == Event::Type::Custom && static_cast<CustomEvent const*>(event.ptr())->custom_type() == custom_event_type;
|
||||
return is_receiver_identical && event_id_matches;
|
||||
});
|
||||
// Event is not in the queue yet, so we want to wake.
|
||||
if (identical_events.is_end())
|
||||
post_event(receiver, make<CustomEvent>(custom_event_type), ShouldWake::Yes);
|
||||
}
|
||||
|
||||
void EventLoop::add_job(NonnullRefPtr<Promise<NonnullRefPtr<Object>>> job_promise)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue