mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-21 08:21:54 +00:00
Once an event loop manager is installed, we want to be sure we only use that manager in the current process going forward. Mixing event loop implementations can only cause problems. More to the point, this ensures that we have installed the AppKit or Qt event loop managers before the first time EventLoopManager::the() is invoked. Now that we defer this installation until we know whether we are running headlessly, we want to be extra sure that we have done so before any services using the event loop have started.
44 lines
1 KiB
C++
44 lines
1 KiB
C++
/*
|
|
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/NonnullOwnPtr.h>
|
|
#include <LibCore/Event.h>
|
|
#include <LibCore/EventLoopImplementation.h>
|
|
#include <LibCore/ThreadEventQueue.h>
|
|
#ifdef AK_OS_WINDOWS
|
|
# include <LibCore/EventLoopImplementationWindows.h>
|
|
#else
|
|
# include <LibCore/EventLoopImplementationUnix.h>
|
|
#endif
|
|
|
|
namespace Core {
|
|
|
|
EventLoopImplementation::EventLoopImplementation()
|
|
: m_thread_event_queue(ThreadEventQueue::current())
|
|
{
|
|
}
|
|
|
|
EventLoopImplementation::~EventLoopImplementation() = default;
|
|
|
|
static EventLoopManager* s_event_loop_manager = nullptr;
|
|
EventLoopManager& EventLoopManager::the()
|
|
{
|
|
if (!s_event_loop_manager)
|
|
s_event_loop_manager = new EventLoopManagerPlatform;
|
|
return *s_event_loop_manager;
|
|
}
|
|
|
|
void EventLoopManager::install(Core::EventLoopManager& manager)
|
|
{
|
|
VERIFY(!s_event_loop_manager);
|
|
s_event_loop_manager = &manager;
|
|
}
|
|
|
|
EventLoopManager::EventLoopManager() = default;
|
|
|
|
EventLoopManager::~EventLoopManager() = default;
|
|
|
|
}
|