From 7704d894965b87c162efdce37dbcb5939579a91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Thu, 11 May 2023 21:58:40 +0200 Subject: [PATCH] LibCore: Cancel jobs on event loop exit This important feature was regressed with the recent architectural change. --- Userland/Libraries/LibCore/EventLoop.cpp | 1 + Userland/Libraries/LibCore/ThreadEventQueue.cpp | 10 ++++++++++ Userland/Libraries/LibCore/ThreadEventQueue.h | 1 + 3 files changed, 12 insertions(+) diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp index e20e9730ef..2d1a0a657d 100644 --- a/Userland/Libraries/LibCore/EventLoop.cpp +++ b/Userland/Libraries/LibCore/EventLoop.cpp @@ -48,6 +48,7 @@ EventLoop& EventLoop::current() void EventLoop::quit(int code) { + ThreadEventQueue::current().cancel_all_pending_jobs(); m_impl->quit(code); } diff --git a/Userland/Libraries/LibCore/ThreadEventQueue.cpp b/Userland/Libraries/LibCore/ThreadEventQueue.cpp index 13e1811800..61a947e653 100644 --- a/Userland/Libraries/LibCore/ThreadEventQueue.cpp +++ b/Userland/Libraries/LibCore/ThreadEventQueue.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace Core { @@ -76,6 +77,15 @@ void ThreadEventQueue::add_job(NonnullRefPtr>> pro m_private->pending_promises.append(move(promise)); } +void ThreadEventQueue::cancel_all_pending_jobs() +{ + Threading::MutexLocker lock(m_private->mutex); + for (auto const& promise : m_private->pending_promises) + promise->cancel(Error::from_errno(ECANCELED)); + + m_private->pending_promises.clear(); +} + size_t ThreadEventQueue::process() { decltype(m_private->queued_events) events; diff --git a/Userland/Libraries/LibCore/ThreadEventQueue.h b/Userland/Libraries/LibCore/ThreadEventQueue.h index 675e7b8e76..76af48da22 100644 --- a/Userland/Libraries/LibCore/ThreadEventQueue.h +++ b/Userland/Libraries/LibCore/ThreadEventQueue.h @@ -29,6 +29,7 @@ public: // Used by Threading::BackgroundAction. void add_job(NonnullRefPtr>>); + void cancel_all_pending_jobs(); // Returns true if there are events waiting to be flushed. bool has_pending_events() const;