mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:58:11 +00:00
LibCore: Big first step towards pluggable Core::EventLoop
The EventLoop is now a wrapper around an EventLoopImplementation. Our old EventLoop code has moved into EventLoopImplementationUnix and continues to work as before. The main difference is that all the separate thread_local variables have been collected into a file-local ThreadData data structure. The goal here is to allow running Core::EventLoop with a totally different backend, such as Qt for Ladybird.
This commit is contained in:
parent
3de8dd921e
commit
16c47ccff6
11 changed files with 718 additions and 562 deletions
51
Userland/Libraries/LibCore/EventLoopImplementationUnix.h
Normal file
51
Userland/Libraries/LibCore/EventLoopImplementationUnix.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibCore/EventLoopImplementation.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class EventLoopImplementationUnix final : public EventLoopImplementation {
|
||||
public:
|
||||
EventLoopImplementationUnix();
|
||||
virtual ~EventLoopImplementationUnix();
|
||||
|
||||
virtual int exec() override;
|
||||
virtual size_t pump(PumpMode) override;
|
||||
virtual void quit(int) override;
|
||||
|
||||
virtual void wake() override;
|
||||
|
||||
virtual void deferred_invoke(Function<void()>) override;
|
||||
|
||||
virtual int register_timer(Object&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible) override;
|
||||
virtual bool unregister_timer(int timer_id) override;
|
||||
|
||||
virtual void register_notifier(Notifier&) override;
|
||||
virtual void unregister_notifier(Notifier&) override;
|
||||
|
||||
virtual void unquit() override;
|
||||
virtual bool was_exit_requested() const override;
|
||||
virtual void notify_forked_and_in_child() override;
|
||||
virtual int register_signal(int signal_number, Function<void(int)> handler) override;
|
||||
virtual void unregister_signal(int handler_id) override;
|
||||
|
||||
private:
|
||||
void wait_for_events(PumpMode);
|
||||
void dispatch_signal(int signal_number);
|
||||
static void handle_signal(int signal_number);
|
||||
static Optional<Time> get_next_timer_expiration();
|
||||
|
||||
bool m_exit_requested { false };
|
||||
int m_exit_code { 0 };
|
||||
|
||||
// The wake pipe of this event loop needs to be accessible from other threads.
|
||||
int (*m_wake_pipe_fds)[2];
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue