mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:37:36 +00:00
LibCore: Allow event loops on other threads to wake up
Because the wake pipe is thread-local, it was previously not possible to wake an event loop across a thread. Therefore, this commit rearchitects event loop waking by making the wake function a member of the event loop itself and having it keep a pointer to its thread's wake pipe. The global wake() function calls wake on the current thread's event loop. This also fixes a bug in BackgroundAction: it should wake the event loop it was created on, instead of the current thread's event loop.
This commit is contained in:
parent
716a3429fa
commit
704bb361bb
4 changed files with 27 additions and 9 deletions
|
@ -34,6 +34,11 @@ public:
|
|||
Yes,
|
||||
};
|
||||
|
||||
enum class ShouldWake {
|
||||
No,
|
||||
Yes
|
||||
};
|
||||
|
||||
explicit EventLoop(MakeInspectable = MakeInspectable::No);
|
||||
~EventLoop();
|
||||
static void initialize_wake_pipes();
|
||||
|
@ -51,7 +56,7 @@ public:
|
|||
|
||||
void spin_until(Function<bool()>);
|
||||
|
||||
void post_event(Object& receiver, NonnullOwnPtr<Event>&&);
|
||||
void post_event(Object& receiver, NonnullOwnPtr<Event>&&, ShouldWake = ShouldWake::No);
|
||||
|
||||
template<typename Callback>
|
||||
static decltype(auto) with_main_locked(Callback callback)
|
||||
|
@ -79,7 +84,8 @@ public:
|
|||
m_queued_events.extend(move(other.m_queued_events));
|
||||
}
|
||||
|
||||
static void wake();
|
||||
static void wake_current();
|
||||
void wake();
|
||||
|
||||
static int register_signal(int signo, Function<void(int)> handler);
|
||||
static void unregister_signal(int handler_id);
|
||||
|
@ -126,6 +132,9 @@ private:
|
|||
static thread_local int s_wake_pipe_fds[2];
|
||||
static thread_local bool s_wake_pipe_initialized;
|
||||
|
||||
// The wake pipe of this event loop needs to be accessible from other threads.
|
||||
int (*m_wake_pipe_fds)[2];
|
||||
|
||||
struct Private;
|
||||
NonnullOwnPtr<Private> m_private;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue