2023-04-24 12:25:14 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
2023-04-24 12:25:14 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibCore/Event.h>
|
|
|
|
|
#include <LibCore/EventLoopImplementation.h>
|
|
|
|
|
#include <LibCore/ThreadEventQueue.h>
|
2024-10-31 12:44:19 +05:00
|
|
|
#ifdef AK_OS_WINDOWS
|
|
|
|
|
# include <LibCore/EventLoopImplementationWindows.h>
|
|
|
|
|
#else
|
|
|
|
|
# include <LibCore/EventLoopImplementationUnix.h>
|
|
|
|
|
#endif
|
2023-04-24 12:25:14 +02:00
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
2023-04-26 18:51:07 +02:00
|
|
|
EventLoopImplementation::EventLoopImplementation()
|
|
|
|
|
: m_thread_event_queue(ThreadEventQueue::current())
|
|
|
|
|
{
|
|
|
|
|
}
|
2023-04-25 17:38:48 +02:00
|
|
|
|
|
|
|
|
EventLoopImplementation::~EventLoopImplementation() = default;
|
|
|
|
|
|
2025-12-03 11:53:04 +01:00
|
|
|
void EventLoopImplementation::deferred_invoke(Function<void()>&& invokee)
|
|
|
|
|
{
|
|
|
|
|
m_thread_event_queue.deferred_invoke(move(invokee));
|
2025-12-29 18:16:54 -06:00
|
|
|
if (&m_thread_event_queue != ThreadEventQueue::current_or_null())
|
|
|
|
|
wake();
|
2025-12-03 11:53:04 +01:00
|
|
|
}
|
|
|
|
|
|
2025-06-13 10:34:07 -04:00
|
|
|
static EventLoopManager* s_event_loop_manager = nullptr;
|
2023-04-25 17:38:48 +02:00
|
|
|
EventLoopManager& EventLoopManager::the()
|
|
|
|
|
{
|
|
|
|
|
if (!s_event_loop_manager)
|
2024-10-31 12:44:19 +05:00
|
|
|
s_event_loop_manager = new EventLoopManagerPlatform;
|
2023-04-25 17:38:48 +02:00
|
|
|
return *s_event_loop_manager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventLoopManager::install(Core::EventLoopManager& manager)
|
|
|
|
|
{
|
2025-06-13 10:34:07 -04:00
|
|
|
VERIFY(!s_event_loop_manager);
|
2023-04-25 17:38:48 +02:00
|
|
|
s_event_loop_manager = &manager;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 18:51:07 +02:00
|
|
|
EventLoopManager::EventLoopManager() = default;
|
2023-04-24 12:25:14 +02:00
|
|
|
|
2023-04-25 17:38:48 +02:00
|
|
|
EventLoopManager::~EventLoopManager() = default;
|
2023-04-24 12:25:14 +02:00
|
|
|
|
|
|
|
|
}
|