summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-04-26 18:51:07 +0200
committerSam Atkins <atkinssj@gmail.com>2023-04-26 19:17:04 +0100
commitb61a87c03cfeb760252d5bdfdd6c666fd74a91e4 (patch)
treecae7629c271064a928958c580f6dc48a9396725a /Userland/Libraries/LibCore
parent7035a19645a745e1fa7c061978598251495d3e01 (diff)
downloadserenity-b61a87c03cfeb760252d5bdfdd6c666fd74a91e4.zip
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.)
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r--Userland/Libraries/LibCore/EventLoop.cpp2
-rw-r--r--Userland/Libraries/LibCore/EventLoopImplementation.cpp19
-rw-r--r--Userland/Libraries/LibCore/EventLoopImplementation.h7
-rw-r--r--Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp14
-rw-r--r--Userland/Libraries/LibCore/EventLoopImplementationUnix.h3
5 files changed, 17 insertions, 28 deletions
diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp
index 330fd31a87..e20e9730ef 100644
--- a/Userland/Libraries/LibCore/EventLoop.cpp
+++ b/Userland/Libraries/LibCore/EventLoop.cpp
@@ -88,7 +88,7 @@ size_t EventLoop::pump(WaitMode mode)
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)
diff --git a/Userland/Libraries/LibCore/EventLoopImplementation.cpp b/Userland/Libraries/LibCore/EventLoopImplementation.cpp
index bc6a39e317..9b14ab2482 100644
--- a/Userland/Libraries/LibCore/EventLoopImplementation.cpp
+++ b/Userland/Libraries/LibCore/EventLoopImplementation.cpp
@@ -12,7 +12,10 @@
namespace Core {
-EventLoopImplementation::EventLoopImplementation() = default;
+EventLoopImplementation::EventLoopImplementation()
+ : m_thread_event_queue(ThreadEventQueue::current())
+{
+}
EventLoopImplementation::~EventLoopImplementation() = default;
@@ -29,20 +32,8 @@ void EventLoopManager::install(Core::EventLoopManager& manager)
s_event_loop_manager = &manager;
}
-EventLoopManager::EventLoopManager()
- : 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();
-}
-
}
diff --git a/Userland/Libraries/LibCore/EventLoopImplementation.h b/Userland/Libraries/LibCore/EventLoopImplementation.h
index ee556b6ec8..d480f85002 100644
--- a/Userland/Libraries/LibCore/EventLoopImplementation.h
+++ b/Userland/Libraries/LibCore/EventLoopImplementation.h
@@ -29,11 +29,8 @@ public:
virtual void register_notifier(Notifier&) = 0;
virtual void unregister_notifier(Notifier&) = 0;
- void post_event(Object& receiver, NonnullOwnPtr<Event>&&);
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.
virtual int register_signal(int signal_number, Function<void(int)> handler) = 0;
virtual void unregister_signal(int handler_id) = 0;
@@ -42,7 +39,6 @@ public:
protected:
EventLoopManager();
- ThreadEventQueue& m_thread_event_queue;
};
class EventLoopImplementation {
@@ -59,6 +55,8 @@ public:
virtual void quit(int) = 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.
virtual void unquit() = 0;
virtual bool was_exit_requested() const = 0;
@@ -66,6 +64,7 @@ public:
protected:
EventLoopImplementation();
+ ThreadEventQueue& m_thread_event_queue;
};
}
diff --git a/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp b/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp
index 1dc525d1f2..a5d94edab4 100644
--- a/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp
+++ b/Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp
@@ -126,6 +126,13 @@ bool EventLoopImplementationUnix::was_exit_requested() const
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()
{
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) }));
}
-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)
{
auto& thread_data = ThreadData::the();
diff --git a/Userland/Libraries/LibCore/EventLoopImplementationUnix.h b/Userland/Libraries/LibCore/EventLoopImplementationUnix.h
index 9e0c9cfe78..4d34c984dd 100644
--- a/Userland/Libraries/LibCore/EventLoopImplementationUnix.h
+++ b/Userland/Libraries/LibCore/EventLoopImplementationUnix.h
@@ -16,8 +16,6 @@ public:
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 bool unregister_timer(int timer_id) override;
@@ -55,6 +53,7 @@ public:
virtual void unquit() override;
virtual bool was_exit_requested() const override;
virtual void notify_forked_and_in_child() override;
+ virtual void post_event(Object& receiver, NonnullOwnPtr<Event>&&) override;
private:
bool m_exit_requested { false };