mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
LibCore: Move post_event() back to EventLoopImplementation
This shouldn't have been moved to EventLoopManager, as the manager is global and one-per-process, and the implementation is one-per-loop. This makes cross-thread event posting work again, and unbreaks SoundPlayer (and probably other things as well.)
This commit is contained in:
parent
7035a19645
commit
b61a87c03c
7 changed files with 22 additions and 35 deletions
|
@ -74,12 +74,11 @@ void EventLoopImplementationQt::wake()
|
||||||
m_event_loop.wakeUp();
|
m_event_loop.wakeUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventLoopManagerQt::deferred_invoke(Function<void()> function)
|
void EventLoopImplementationQt::post_event(Core::Object& receiver, NonnullOwnPtr<Core::Event>&& event)
|
||||||
{
|
{
|
||||||
VERIFY(function);
|
m_thread_event_queue.post_event(receiver, move(event));
|
||||||
QTimer::singleShot(0, [function = move(function)] {
|
if (&m_thread_event_queue != &Core::ThreadEventQueue::current())
|
||||||
function();
|
wake();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qt_timer_fired(int timer_id, Core::TimerShouldFireWhenNotVisible should_fire_when_not_visible, Core::Object& object)
|
static void qt_timer_fired(int timer_id, Core::TimerShouldFireWhenNotVisible should_fire_when_not_visible, Core::Object& object)
|
||||||
|
|
|
@ -22,8 +22,6 @@ public:
|
||||||
virtual ~EventLoopManagerQt() override;
|
virtual ~EventLoopManagerQt() override;
|
||||||
virtual NonnullOwnPtr<Core::EventLoopImplementation> make_implementation() override;
|
virtual NonnullOwnPtr<Core::EventLoopImplementation> make_implementation() override;
|
||||||
|
|
||||||
virtual void deferred_invoke(Function<void()>) override;
|
|
||||||
|
|
||||||
virtual int register_timer(Core::Object&, int milliseconds, bool should_reload, Core::TimerShouldFireWhenNotVisible) override;
|
virtual int register_timer(Core::Object&, int milliseconds, bool should_reload, Core::TimerShouldFireWhenNotVisible) override;
|
||||||
virtual bool unregister_timer(int timer_id) override;
|
virtual bool unregister_timer(int timer_id) override;
|
||||||
|
|
||||||
|
@ -52,6 +50,7 @@ public:
|
||||||
virtual size_t pump(PumpMode) override;
|
virtual size_t pump(PumpMode) override;
|
||||||
virtual void quit(int) override;
|
virtual void quit(int) override;
|
||||||
virtual void wake() override;
|
virtual void wake() override;
|
||||||
|
virtual void post_event(Core::Object& receiver, NonnullOwnPtr<Core::Event>&&) override;
|
||||||
|
|
||||||
// FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
|
// FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
|
||||||
virtual void unquit() override { }
|
virtual void unquit() override { }
|
||||||
|
|
|
@ -88,7 +88,7 @@ size_t EventLoop::pump(WaitMode mode)
|
||||||
|
|
||||||
void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
|
void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
|
||||||
{
|
{
|
||||||
EventLoopManager::the().post_event(receiver, move(event));
|
m_impl->post_event(receiver, move(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventLoop::add_job(NonnullRefPtr<Promise<NonnullRefPtr<Object>>> job_promise)
|
void EventLoop::add_job(NonnullRefPtr<Promise<NonnullRefPtr<Object>>> job_promise)
|
||||||
|
|
|
@ -12,7 +12,10 @@
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
EventLoopImplementation::EventLoopImplementation() = default;
|
EventLoopImplementation::EventLoopImplementation()
|
||||||
|
: m_thread_event_queue(ThreadEventQueue::current())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
EventLoopImplementation::~EventLoopImplementation() = default;
|
EventLoopImplementation::~EventLoopImplementation() = default;
|
||||||
|
|
||||||
|
@ -29,20 +32,8 @@ void EventLoopManager::install(Core::EventLoopManager& manager)
|
||||||
s_event_loop_manager = &manager;
|
s_event_loop_manager = &manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventLoopManager::EventLoopManager()
|
EventLoopManager::EventLoopManager() = default;
|
||||||
: m_thread_event_queue(ThreadEventQueue::current())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
EventLoopManager::~EventLoopManager() = default;
|
EventLoopManager::~EventLoopManager() = default;
|
||||||
|
|
||||||
void EventLoopManager::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
|
|
||||||
{
|
|
||||||
m_thread_event_queue.post_event(receiver, move(event));
|
|
||||||
|
|
||||||
// Wake up this EventLoopImplementation if this is a cross-thread event posting.
|
|
||||||
if (&ThreadEventQueue::current() != &m_thread_event_queue)
|
|
||||||
wake();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,8 @@ public:
|
||||||
virtual void register_notifier(Notifier&) = 0;
|
virtual void register_notifier(Notifier&) = 0;
|
||||||
virtual void unregister_notifier(Notifier&) = 0;
|
virtual void unregister_notifier(Notifier&) = 0;
|
||||||
|
|
||||||
void post_event(Object& receiver, NonnullOwnPtr<Event>&&);
|
|
||||||
virtual void did_post_event() = 0;
|
virtual void did_post_event() = 0;
|
||||||
|
|
||||||
virtual void deferred_invoke(Function<void()>) = 0;
|
|
||||||
|
|
||||||
// FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
|
// FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
|
||||||
virtual int register_signal(int signal_number, Function<void(int)> handler) = 0;
|
virtual int register_signal(int signal_number, Function<void(int)> handler) = 0;
|
||||||
virtual void unregister_signal(int handler_id) = 0;
|
virtual void unregister_signal(int handler_id) = 0;
|
||||||
|
@ -42,7 +39,6 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
EventLoopManager();
|
EventLoopManager();
|
||||||
ThreadEventQueue& m_thread_event_queue;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class EventLoopImplementation {
|
class EventLoopImplementation {
|
||||||
|
@ -59,6 +55,8 @@ public:
|
||||||
virtual void quit(int) = 0;
|
virtual void quit(int) = 0;
|
||||||
virtual void wake() = 0;
|
virtual void wake() = 0;
|
||||||
|
|
||||||
|
virtual void post_event(Object& receiver, NonnullOwnPtr<Event>&&) = 0;
|
||||||
|
|
||||||
// FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
|
// FIXME: These APIs only exist for obscure use-cases inside SerenityOS. Try to get rid of them.
|
||||||
virtual void unquit() = 0;
|
virtual void unquit() = 0;
|
||||||
virtual bool was_exit_requested() const = 0;
|
virtual bool was_exit_requested() const = 0;
|
||||||
|
@ -66,6 +64,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
EventLoopImplementation();
|
EventLoopImplementation();
|
||||||
|
ThreadEventQueue& m_thread_event_queue;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,13 @@ bool EventLoopImplementationUnix::was_exit_requested() const
|
||||||
return m_exit_requested;
|
return m_exit_requested;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EventLoopImplementationUnix::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
|
||||||
|
{
|
||||||
|
m_thread_event_queue.post_event(receiver, move(event));
|
||||||
|
if (&m_thread_event_queue != &ThreadEventQueue::current())
|
||||||
|
wake();
|
||||||
|
}
|
||||||
|
|
||||||
void EventLoopImplementationUnix::wake()
|
void EventLoopImplementationUnix::wake()
|
||||||
{
|
{
|
||||||
int wake_event = 0;
|
int wake_event = 0;
|
||||||
|
@ -138,13 +145,6 @@ void EventLoopManagerUnix::wake()
|
||||||
MUST(Core::System::write(ThreadData::the().wake_pipe_fds[1], { &wake_event, sizeof(wake_event) }));
|
MUST(Core::System::write(ThreadData::the().wake_pipe_fds[1], { &wake_event, sizeof(wake_event) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventLoopManagerUnix::deferred_invoke(Function<void()> invokee)
|
|
||||||
{
|
|
||||||
// FIXME: Get rid of the useless DeferredInvocationContext object.
|
|
||||||
auto context = DeferredInvocationContext::construct();
|
|
||||||
post_event(context, make<DeferredInvocationEvent>(context, move(invokee)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventLoopManagerUnix::wait_for_events(EventLoopImplementation::PumpMode mode)
|
void EventLoopManagerUnix::wait_for_events(EventLoopImplementation::PumpMode mode)
|
||||||
{
|
{
|
||||||
auto& thread_data = ThreadData::the();
|
auto& thread_data = ThreadData::the();
|
||||||
|
|
|
@ -16,8 +16,6 @@ public:
|
||||||
|
|
||||||
virtual NonnullOwnPtr<EventLoopImplementation> make_implementation() override;
|
virtual NonnullOwnPtr<EventLoopImplementation> make_implementation() override;
|
||||||
|
|
||||||
virtual void deferred_invoke(Function<void()>) override;
|
|
||||||
|
|
||||||
virtual int register_timer(Object&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible) override;
|
virtual int register_timer(Object&, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible) override;
|
||||||
virtual bool unregister_timer(int timer_id) override;
|
virtual bool unregister_timer(int timer_id) override;
|
||||||
|
|
||||||
|
@ -55,6 +53,7 @@ public:
|
||||||
virtual void unquit() override;
|
virtual void unquit() override;
|
||||||
virtual bool was_exit_requested() const override;
|
virtual bool was_exit_requested() const override;
|
||||||
virtual void notify_forked_and_in_child() override;
|
virtual void notify_forked_and_in_child() override;
|
||||||
|
virtual void post_event(Object& receiver, NonnullOwnPtr<Event>&&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_exit_requested { false };
|
bool m_exit_requested { false };
|
||||||
|
|
Loading…
Add table
Reference in a new issue