ladybird/Userland/Libraries/LibCore/EventLoopImplementation.cpp
Andreas Kling 16c47ccff6 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.
2023-04-25 14:48:40 +02:00

30 lines
768 B
C++

/*
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/NonnullOwnPtr.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoopImplementation.h>
#include <LibCore/ThreadEventQueue.h>
namespace Core {
EventLoopImplementation::EventLoopImplementation()
: m_thread_event_queue(ThreadEventQueue::current())
{
}
EventLoopImplementation::~EventLoopImplementation() = default;
void EventLoopImplementation::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();
}
}