Commit Graph

13 Commits

Author SHA1 Message Date
sin-ack
e9121f8b1f LibCore+Userland: Implement Core::deferred_invoke
Core::deferred_invoke is a way of executing an action after previously
queued events have been processed. It removes the requirement of
having/being a Core::Object subclass in order to defer invocation
through Core::Object::deferred_invoke.

Core::Object::deferred_invoke now delegates to Core::deferred_invoke.
The version with the Object& argument is still present but will be
removed in the following commits.

This commit additionally fixes a new places where the
DeferredInvocationEvent was dispatched to the event loop directly, and
replaces them with the Core::deferred_invoke equivalent.
2021-09-02 03:47:47 +04:30
Andreas Kling
2e3df52862 Revert "LibThreading: Fix BackgroundAction result use-after-free"
This reverts commit b2e6088bff.

This was a speculative fix that ended up not fixing the issue.
2021-07-12 11:29:37 +02:00
Andreas Kling
b8a204c5b9 LibThreading: Rename Lock => Mutex 2021-07-09 11:15:50 +02:00
Andreas Kling
ce5d2b4f16 LibThreading: Remove unused "Lockable" class 2021-07-09 11:15:50 +02:00
Andreas Kling
fd155193e7 LibThreading: Use a condvar to signal the BackgroundAction thread
Now that pthread_cond_t works correctly thanks to Sergey, we can use
them to wake up the BackgroundAction worker thread instead of making
a Unix pipe. :^)
2021-07-07 18:02:43 +02:00
Gunnar Beutner
f3a3a63b68 LibThread: Fix formatting that was broken by the previous commit 2021-07-06 00:14:19 +02:00
Gunnar Beutner
01db5205ab LibThreading: Fix building the library on macOS 2021-07-06 00:06:32 +02:00
Andreas Kling
c40780d404 LibThreading: Reimplement Lock in terms of pthread_mutex_t
This class was previously a spinlock that would call sys$donate()
to donate its timeslice to whichever thread was holding the lock.

Now that pthread_mutex_t has a fast path, let's implement Lock on top
of that instead and get rid of the last remaining user of sys$donate().
2021-07-05 23:30:15 +02:00
Tom
b2e6088bff LibThreading: Fix BackgroundAction result use-after-free
We need to move the result out of the BackgroundAction object before
posting the completion callback as there is a chance the
BackgroundAction instance gets freed before the event loop runs our
callback.

Fixes #7641
2021-07-05 18:11:58 +02:00
Andreas Kling
e8579ed24a 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. :^)
2021-07-04 18:56:08 +02:00
Spencer Dixon
48731e9f17 LibThreading: Add new detach() API to Thread
Sometimes you don't care about `joining()` the result of a thread. The
underlying pthread implementation already existed for detaching and
now we expose it to the higher level API.
2021-07-02 17:52:45 +02:00
Spencer Dixon
00f93b2545 LibThreading: Add ability to cancel ongoing BackgroundActions
Handlers of the BackgroundAction are responsible for checking if the
action has been cancelled and returning early.
2021-07-02 16:47:14 +02:00
Andreas Kling
b5d73c834f Userland: Rename LibThread => LibThreading
Also rename the "LibThread" namespace to "Threading"
2021-05-22 18:54:22 +02:00