mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:28:11 +00:00
LibThreading: Wake up the background worker thread when there's work
The worker thread used for BackgroundAction was going to sleep for 1 second at a time (when there was nothing to do.) This made using background actions for anything interactive quite unresponsive since you had to wait up to 1 second before it even started on your task. We now use a simple Unix pipe to signal the worker thread that a new work item is available. This makes Assistant way more responsive when typing. :^)
This commit is contained in:
parent
d114ba4c4e
commit
e8579ed24a
2 changed files with 36 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -13,7 +14,6 @@
|
|||
#include <LibCore/Event.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibThreading/Lock.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
|
||||
namespace Threading {
|
||||
|
@ -28,7 +28,7 @@ class BackgroundActionBase {
|
|||
private:
|
||||
BackgroundActionBase() { }
|
||||
|
||||
static Lockable<Queue<Function<void()>>>& all_actions();
|
||||
static void enqueue_work(Function<void()>);
|
||||
static Thread& background_thread();
|
||||
};
|
||||
|
||||
|
@ -63,9 +63,7 @@ private:
|
|||
, m_action(move(action))
|
||||
, m_on_complete(move(on_complete))
|
||||
{
|
||||
Locker locker(all_actions().lock());
|
||||
|
||||
all_actions().resource().enqueue([this] {
|
||||
enqueue_work([this] {
|
||||
m_result = m_action(*this);
|
||||
if (m_on_complete) {
|
||||
Core::EventLoop::current().post_event(*this, make<Core::DeferredInvocationEvent>([this](auto&) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue