mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 05:05:08 +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
30
Userland/Libraries/LibCore/EventLoopImplementation.cpp
Normal file
30
Userland/Libraries/LibCore/EventLoopImplementation.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue