From b50d03f42ecdb499715c28dfb92f2e1fe6df34b7 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 29 Apr 2025 15:41:18 -0600 Subject: [PATCH] LibCore+LibWebView: Restore was_exit_requested to EventLoop This method was removed in e015a43b51192be888638d3da752c488e85b54d2 However, it was not exactly *unused* as the commit message would say. This method was the only thing that allowed spin_until to exit when the event loop was cancelled. This happens normally when IPC connections are closed, but also when the process is killed. The logic to properly handle process exit from event loop spins needs to actually notify the caller that their goal condition was not met though. That will be handled in a later commit. --- Libraries/LibCore/EventLoop.cpp | 5 +++++ Libraries/LibCore/EventLoop.h | 2 ++ Libraries/LibCore/EventLoopImplementation.h | 1 + Libraries/LibCore/EventLoopImplementationUnix.h | 1 + Libraries/LibCore/EventLoopImplementationWindows.h | 2 +- .../LibWebView/EventLoop/EventLoopImplementationMacOS.h | 1 + .../LibWebView/EventLoop/EventLoopImplementationMacOS.mm | 5 +++++ .../LibWebView/EventLoop/EventLoopImplementationQt.cpp | 7 +++++++ Libraries/LibWebView/EventLoop/EventLoopImplementationQt.h | 2 ++ 9 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Libraries/LibCore/EventLoop.cpp b/Libraries/LibCore/EventLoop.cpp index d8a164fdf39..b66a73f74b7 100644 --- a/Libraries/LibCore/EventLoop.cpp +++ b/Libraries/LibCore/EventLoop.cpp @@ -65,6 +65,11 @@ void EventLoop::quit(int code) m_impl->quit(code); } +bool EventLoop::was_exit_requested() +{ + return m_impl->was_exit_requested(); +} + struct EventLoopPusher { public: EventLoopPusher(EventLoop& event_loop) diff --git a/Libraries/LibCore/EventLoop.h b/Libraries/LibCore/EventLoop.h index 9240d6da8e6..076d2b742fb 100644 --- a/Libraries/LibCore/EventLoop.h +++ b/Libraries/LibCore/EventLoop.h @@ -78,6 +78,8 @@ public: void quit(int); + bool was_exit_requested(); + // The registration functions act upon the current loop of the current thread. static intptr_t register_timer(EventReceiver&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible); static void unregister_timer(intptr_t timer_id); diff --git a/Libraries/LibCore/EventLoopImplementation.h b/Libraries/LibCore/EventLoopImplementation.h index f1929417b45..a4c87e62c68 100644 --- a/Libraries/LibCore/EventLoopImplementation.h +++ b/Libraries/LibCore/EventLoopImplementation.h @@ -52,6 +52,7 @@ public: virtual size_t pump(PumpMode) = 0; virtual void quit(int) = 0; virtual void wake() = 0; + virtual bool was_exit_requested() const = 0; virtual void post_event(EventReceiver& receiver, NonnullOwnPtr&&) = 0; diff --git a/Libraries/LibCore/EventLoopImplementationUnix.h b/Libraries/LibCore/EventLoopImplementationUnix.h index 3c697c0e715..2adbe5ab730 100644 --- a/Libraries/LibCore/EventLoopImplementationUnix.h +++ b/Libraries/LibCore/EventLoopImplementationUnix.h @@ -46,6 +46,7 @@ public: virtual int exec() override; virtual size_t pump(PumpMode) override; virtual void quit(int) override; + virtual bool was_exit_requested() const override { return m_exit_requested; } virtual void wake() override; diff --git a/Libraries/LibCore/EventLoopImplementationWindows.h b/Libraries/LibCore/EventLoopImplementationWindows.h index 72e721e821c..2217a0b5a1e 100644 --- a/Libraries/LibCore/EventLoopImplementationWindows.h +++ b/Libraries/LibCore/EventLoopImplementationWindows.h @@ -39,8 +39,8 @@ public: virtual int exec() override; virtual size_t pump(PumpMode) override; virtual void quit(int) override; - virtual void wake() override; + virtual bool was_exit_requested() const override { return m_exit_requested; } virtual void post_event(EventReceiver& receiver, NonnullOwnPtr&&) override; diff --git a/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.h b/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.h index bee5c580c77..03197c448b3 100644 --- a/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.h +++ b/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.h @@ -39,6 +39,7 @@ public: virtual size_t pump(PumpMode) override; virtual void quit(int) override; virtual void wake() override; + virtual bool was_exit_requested() const override; virtual void post_event(Core::EventReceiver& receiver, NonnullOwnPtr&&) override; private: diff --git a/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.mm b/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.mm index a4ceea854cd..1fdc9f427f9 100644 --- a/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.mm +++ b/Libraries/LibWebView/EventLoop/EventLoopImplementationMacOS.mm @@ -404,6 +404,11 @@ void EventLoopImplementationMacOS::wake() CFRunLoopWakeUp(CFRunLoopGetCurrent()); } +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)); diff --git a/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.cpp b/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.cpp index 18a7fb6bd70..02e0a850c65 100644 --- a/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.cpp +++ b/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.cpp @@ -222,6 +222,13 @@ void EventLoopImplementationQt::wake() m_event_loop->wakeUp(); } +bool EventLoopImplementationQt::was_exit_requested() const +{ + if (is_main_loop()) + return QCoreApplication::closingDown(); + return !m_event_loop->isRunning(); +} + void EventLoopImplementationQt::post_event(Core::EventReceiver& receiver, NonnullOwnPtr&& event) { m_thread_event_queue.post_event(receiver, move(event)); diff --git a/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.h b/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.h index 00104d6f37f..3a0777533a7 100644 --- a/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.h +++ b/Libraries/LibWebView/EventLoop/EventLoopImplementationQt.h @@ -57,6 +57,8 @@ public: virtual size_t pump(PumpMode) override; virtual void quit(int) override; virtual void wake() override; + virtual bool was_exit_requested() const override; + virtual void post_event(Core::EventReceiver& receiver, NonnullOwnPtr&&) override; void set_main_loop();