mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:38:12 +00:00
LibCore: Cancel jobs on event loop exit
This important feature was regressed with the recent architectural change.
This commit is contained in:
parent
f2609281a3
commit
7704d89496
3 changed files with 12 additions and 0 deletions
|
@ -48,6 +48,7 @@ EventLoop& EventLoop::current()
|
|||
|
||||
void EventLoop::quit(int code)
|
||||
{
|
||||
ThreadEventQueue::current().cancel_all_pending_jobs();
|
||||
m_impl->quit(code);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <LibCore/Promise.h>
|
||||
#include <LibCore/ThreadEventQueue.h>
|
||||
#include <LibThreading/Mutex.h>
|
||||
#include <errno.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
@ -76,6 +77,15 @@ void ThreadEventQueue::add_job(NonnullRefPtr<Promise<NonnullRefPtr<Object>>> 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;
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
|
||||
// Used by Threading::BackgroundAction.
|
||||
void add_job(NonnullRefPtr<Promise<NonnullRefPtr<Object>>>);
|
||||
void cancel_all_pending_jobs();
|
||||
|
||||
// Returns true if there are events waiting to be flushed.
|
||||
bool has_pending_events() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue