diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-04 18:01:01 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-04 18:56:08 +0200 |
commit | e8579ed24a00e95deabbcfe3486d73ca541bc68c (patch) | |
tree | 39705174be706443308ee759420e3511b3f7b913 /Userland/Libraries/LibThreading/BackgroundAction.h | |
parent | d114ba4c4e52d52755ad8b874e3ab4ec67b794e7 (diff) | |
download | serenity-e8579ed24a00e95deabbcfe3486d73ca541bc68c.zip |
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. :^)
Diffstat (limited to 'Userland/Libraries/LibThreading/BackgroundAction.h')
-rw-r--r-- | Userland/Libraries/LibThreading/BackgroundAction.h | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/Userland/Libraries/LibThreading/BackgroundAction.h b/Userland/Libraries/LibThreading/BackgroundAction.h index 2ac77d5758..d169ae4aa3 100644 --- a/Userland/Libraries/LibThreading/BackgroundAction.h +++ b/Userland/Libraries/LibThreading/BackgroundAction.h @@ -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&) { |