From cebc4d00ddf9c6c5c9a0c166c55c8f72aea40e9c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 3 Dec 2025 12:00:22 +0100 Subject: [PATCH] LibCore: Remove ability to post heap-allocated Core::Event objects We no longer need this API since all clients have been converted to simply posting the Core::Event::Type (or a callback function). --- Libraries/LibCore/EventLoop.cpp | 5 ----- Libraries/LibCore/EventLoop.h | 3 --- Libraries/LibCore/EventLoopImplementation.h | 2 -- .../LibCore/EventLoopImplementationUnix.cpp | 7 ------- .../LibCore/EventLoopImplementationUnix.h | 2 -- .../EventLoopImplementationWindows.cpp | 7 ------- .../LibCore/EventLoopImplementationWindows.h | 2 -- Libraries/LibCore/ThreadEventQueue.cpp | 20 +------------------ Libraries/LibCore/ThreadEventQueue.h | 1 - .../EventLoop/EventLoopImplementationMacOS.h | 1 - .../EventLoop/EventLoopImplementationMacOS.mm | 10 ---------- .../EventLoop/EventLoopImplementationQt.cpp | 7 ------- .../EventLoop/EventLoopImplementationQt.h | 2 -- .../main/cpp/ALooperEventLoopImplementation.h | 1 - 14 files changed, 1 insertion(+), 69 deletions(-) diff --git a/Libraries/LibCore/EventLoop.cpp b/Libraries/LibCore/EventLoop.cpp index 7afce6c28f1..6f588bbd0a0 100644 --- a/Libraries/LibCore/EventLoop.cpp +++ b/Libraries/LibCore/EventLoop.cpp @@ -102,11 +102,6 @@ size_t EventLoop::pump(WaitMode mode) return m_impl->pump(mode == WaitMode::WaitForEvents ? EventLoopImplementation::PumpMode::WaitForEvents : EventLoopImplementation::PumpMode::DontWaitForEvents); } -void EventLoop::post_event(EventReceiver& receiver, NonnullOwnPtr&& event) -{ - m_impl->post_event(&receiver, move(event)); -} - void EventLoop::add_job(NonnullRefPtr>> job_promise) { ThreadEventQueue::current().add_job(move(job_promise)); diff --git a/Libraries/LibCore/EventLoop.h b/Libraries/LibCore/EventLoop.h index 5b12d7baeee..f89f3d6f08d 100644 --- a/Libraries/LibCore/EventLoop.h +++ b/Libraries/LibCore/EventLoop.h @@ -67,9 +67,6 @@ public: // Pump the event loop until some condition is met. void spin_until(Function); - // Post an event to this event loop. - void post_event(EventReceiver& receiver, NonnullOwnPtr&&); - void add_job(NonnullRefPtr>> job_promise); void deferred_invoke(ESCAPING Function); diff --git a/Libraries/LibCore/EventLoopImplementation.h b/Libraries/LibCore/EventLoopImplementation.h index 8f13a01e58c..76212ccd649 100644 --- a/Libraries/LibCore/EventLoopImplementation.h +++ b/Libraries/LibCore/EventLoopImplementation.h @@ -54,8 +54,6 @@ public: virtual void wake() = 0; virtual bool was_exit_requested() const = 0; - virtual void post_event(EventReceiver*, NonnullOwnPtr&&) = 0; - virtual void deferred_invoke(Function&&); protected: diff --git a/Libraries/LibCore/EventLoopImplementationUnix.cpp b/Libraries/LibCore/EventLoopImplementationUnix.cpp index a308dbe94de..dd065b63d52 100644 --- a/Libraries/LibCore/EventLoopImplementationUnix.cpp +++ b/Libraries/LibCore/EventLoopImplementationUnix.cpp @@ -314,13 +314,6 @@ void EventLoopImplementationUnix::quit(int code) m_exit_code = code; } -void EventLoopImplementationUnix::post_event(EventReceiver* receiver, NonnullOwnPtr&& event) -{ - m_thread_event_queue.post_event(receiver, move(event)); - if (&m_thread_event_queue != &ThreadEventQueue::current()) - wake(); -} - void EventLoopImplementationUnix::wake() { int wake_event = 0; diff --git a/Libraries/LibCore/EventLoopImplementationUnix.h b/Libraries/LibCore/EventLoopImplementationUnix.h index f55035569e2..7ad53acd22a 100644 --- a/Libraries/LibCore/EventLoopImplementationUnix.h +++ b/Libraries/LibCore/EventLoopImplementationUnix.h @@ -51,8 +51,6 @@ public: virtual void wake() override; - virtual void post_event(EventReceiver*, NonnullOwnPtr&&) override; - private: bool m_exit_requested { false }; int m_exit_code { 0 }; diff --git a/Libraries/LibCore/EventLoopImplementationWindows.cpp b/Libraries/LibCore/EventLoopImplementationWindows.cpp index 07cb3dec6bf..75b3e5a8f12 100644 --- a/Libraries/LibCore/EventLoopImplementationWindows.cpp +++ b/Libraries/LibCore/EventLoopImplementationWindows.cpp @@ -232,13 +232,6 @@ void EventLoopImplementationWindows::quit(int code) m_exit_code = code; } -void EventLoopImplementationWindows::post_event(EventReceiver* receiver, NonnullOwnPtr&& event) -{ - m_thread_event_queue.post_event(receiver, move(event)); - if (&m_thread_event_queue != &ThreadEventQueue::current()) - wake(); -} - void EventLoopImplementationWindows::wake() { SetEvent(m_wake_event); diff --git a/Libraries/LibCore/EventLoopImplementationWindows.h b/Libraries/LibCore/EventLoopImplementationWindows.h index b4ac01a287c..283b833e2f3 100644 --- a/Libraries/LibCore/EventLoopImplementationWindows.h +++ b/Libraries/LibCore/EventLoopImplementationWindows.h @@ -42,8 +42,6 @@ public: virtual void wake() override; virtual bool was_exit_requested() const override { return m_exit_requested; } - virtual void post_event(EventReceiver*, NonnullOwnPtr&&) override; - private: bool m_exit_requested { false }; int m_exit_code { 0 }; diff --git a/Libraries/LibCore/ThreadEventQueue.cpp b/Libraries/LibCore/ThreadEventQueue.cpp index 72cd3bc4d25..8b719c4e6f3 100644 --- a/Libraries/LibCore/ThreadEventQueue.cpp +++ b/Libraries/LibCore/ThreadEventQueue.cpp @@ -21,13 +21,6 @@ struct ThreadEventQueue::Private { AK_MAKE_DEFAULT_MOVABLE(QueuedEvent); public: - QueuedEvent(RefPtr const& receiver, NonnullOwnPtr event) - : receiver(receiver) - , event(move(event)) - , event_type(this->event->type()) - { - } - QueuedEvent(RefPtr const& receiver, Event::Type event_type) : receiver(receiver) , event_type(event_type) @@ -43,7 +36,6 @@ struct ThreadEventQueue::Private { ~QueuedEvent() = default; WeakPtr receiver; - OwnPtr event; Function m_invokee; u8 event_type { Event::Type::Invalid }; }; @@ -81,15 +73,6 @@ ThreadEventQueue::ThreadEventQueue() ThreadEventQueue::~ThreadEventQueue() = default; -void ThreadEventQueue::post_event(Core::EventReceiver* receiver, NonnullOwnPtr event) -{ - { - Threading::MutexLocker lock(m_private->mutex); - m_private->queued_events.empend(receiver, move(event)); - } - Core::EventLoopManager::the().did_post_event(); -} - void ThreadEventQueue::post_event(Core::EventReceiver* receiver, Core::Event::Type event_type) { { @@ -147,8 +130,7 @@ size_t ThreadEventQueue::process() break; } default: - receiver->dispatch_event(*queued_event.event); - break; + VERIFY_NOT_REACHED(); } } else { if (queued_event.event_type == Event::Type::DeferredInvoke) { diff --git a/Libraries/LibCore/ThreadEventQueue.h b/Libraries/LibCore/ThreadEventQueue.h index 5ef23e64914..b2d6e311db1 100644 --- a/Libraries/LibCore/ThreadEventQueue.h +++ b/Libraries/LibCore/ThreadEventQueue.h @@ -26,7 +26,6 @@ public: size_t process(); // Posts an event to the event queue. - void post_event(EventReceiver*, NonnullOwnPtr); void post_event(EventReceiver*, Core::Event::Type); // Post a deferred invocation to the event queue. diff --git a/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.h b/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.h index 24751dab1d4..71e00145f99 100644 --- a/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.h +++ b/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.h @@ -41,7 +41,6 @@ public: virtual void quit(int) override; virtual void wake() override; virtual bool was_exit_requested() const override; - virtual void post_event(Core::EventReceiver*, NonnullOwnPtr&&) override; virtual ~EventLoopImplementationMacOS() override; diff --git a/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.mm b/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.mm index 43795e61fdb..3ef870c8ccb 100644 --- a/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.mm +++ b/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.mm @@ -485,14 +485,4 @@ bool EventLoopImplementationMacOS::was_exit_requested() const return ![NSApp isRunning]; } -void EventLoopImplementationMacOS::post_event(Core::EventReceiver* receiver, NonnullOwnPtr&& event) -{ - m_thread_event_queue.post_event(receiver, move(event)); - - bool expected = false; - if (m_impl->deferred_source && m_impl->deferred_source_pending.compare_exchange_strong(expected, true)) { - CFRunLoopSourceSignal(m_impl->deferred_source); - } -} - } diff --git a/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.cpp b/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.cpp index 70462432f5e..08e81789bc4 100644 --- a/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.cpp +++ b/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.cpp @@ -252,13 +252,6 @@ bool EventLoopImplementationQt::was_exit_requested() const return !m_event_loop->isRunning(); } -void EventLoopImplementationQt::post_event(Core::EventReceiver* receiver, NonnullOwnPtr&& event) -{ - m_thread_event_queue.post_event(receiver, move(event)); - if (&m_thread_event_queue != &Core::ThreadEventQueue::current()) - wake(); -} - void EventLoopImplementationQt::set_main_loop() { m_main_loop = true; diff --git a/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.h b/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.h index 1a990030b25..59a7298a8b8 100644 --- a/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.h +++ b/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.h @@ -59,8 +59,6 @@ public: virtual void wake() override; virtual bool was_exit_requested() const override; - virtual void post_event(Core::EventReceiver*, NonnullOwnPtr&&) override; - void set_main_loop(); private: diff --git a/UI/Android/src/main/cpp/ALooperEventLoopImplementation.h b/UI/Android/src/main/cpp/ALooperEventLoopImplementation.h index fa6de7c4486..999ea52cc3e 100644 --- a/UI/Android/src/main/cpp/ALooperEventLoopImplementation.h +++ b/UI/Android/src/main/cpp/ALooperEventLoopImplementation.h @@ -69,7 +69,6 @@ public: virtual size_t pump(PumpMode) override; virtual void quit(int) override; virtual void wake() override; - virtual void post_event(Core::EventReceiver& receiver, NonnullOwnPtr&&) override; virtual bool was_exit_requested() const override { return false; }