mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibCore: Don't require heap-allocated event to hold deferred invocation
Instead of creating a DeferredInvocationEvent every time we deferred_invoke, we now let the QueuedEvent store the invokee Function object directly.
This commit is contained in:
parent
69515f8c85
commit
2a1c5dc108
Notes:
github-actions[bot]
2025-12-03 12:27:45 +00:00
Author: https://github.com/awesomekling
Commit: 2a1c5dc108
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7004
6 changed files with 28 additions and 17 deletions
|
|
@ -34,10 +34,17 @@ struct ThreadEventQueue::Private {
|
|||
{
|
||||
}
|
||||
|
||||
QueuedEvent(Function<void()>&& invokee)
|
||||
: m_invokee(move(invokee))
|
||||
, event_type(Event::Type::DeferredInvoke)
|
||||
{
|
||||
}
|
||||
|
||||
~QueuedEvent() = default;
|
||||
|
||||
WeakPtr<EventReceiver> receiver;
|
||||
OwnPtr<Event> event;
|
||||
Function<void()> m_invokee;
|
||||
u8 event_type { Event::Type::Invalid };
|
||||
};
|
||||
|
||||
|
|
@ -92,6 +99,15 @@ void ThreadEventQueue::post_event(Core::EventReceiver* receiver, Core::Event::Ty
|
|||
Core::EventLoopManager::the().did_post_event();
|
||||
}
|
||||
|
||||
void ThreadEventQueue::deferred_invoke(Function<void()>&& invokee)
|
||||
{
|
||||
{
|
||||
Threading::MutexLocker lock(m_private->mutex);
|
||||
m_private->queued_events.empend(move(invokee));
|
||||
}
|
||||
Core::EventLoopManager::the().did_post_event();
|
||||
}
|
||||
|
||||
void ThreadEventQueue::add_job(NonnullRefPtr<Promise<NonnullRefPtr<EventReceiver>>> promise)
|
||||
{
|
||||
Threading::MutexLocker lock(m_private->mutex);
|
||||
|
|
@ -136,7 +152,7 @@ size_t ThreadEventQueue::process()
|
|||
}
|
||||
} else {
|
||||
if (queued_event.event_type == Event::Type::DeferredInvoke) {
|
||||
static_cast<DeferredInvocationEvent&>(*queued_event.event).m_invokee();
|
||||
queued_event.m_invokee();
|
||||
} else {
|
||||
// Receiver gone, drop the event.
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue