mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02:00
Add a thread-safe deferred_invoke() API on WeakEventLoopReference that queues work onto the owning thread's event queue and wakes that thread via EventLoopManager hooks. This avoids calling wake() from foreign threads during teardown. Implement current_thread_handle()/wake_thread() in each backend and track per-thread data so handles are validated before waking: - Unix: wake via per-thread wake pipe - Windows: wake via thread wake event - macOS: wake via stored CFRunLoopRef - Qt: wake via event target or QEventLoop::wakeUp() - Android: wake via stored ALooper
59 lines
1.9 KiB
C++
59 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) 2023-2025, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Function.h>
|
|
#include <AK/NonnullOwnPtr.h>
|
|
#include <LibCore/EventLoopImplementation.h>
|
|
|
|
namespace Ladybird {
|
|
|
|
class EventLoopManagerMacOS final : public Core::EventLoopManager {
|
|
public:
|
|
virtual NonnullOwnPtr<Core::EventLoopImplementation> make_implementation() override;
|
|
|
|
virtual intptr_t register_timer(Core::EventReceiver&, int interval_milliseconds, bool should_reload) override;
|
|
virtual void unregister_timer(intptr_t timer_id) override;
|
|
|
|
virtual void register_notifier(Core::Notifier&) override;
|
|
virtual void unregister_notifier(Core::Notifier&) override;
|
|
|
|
virtual void did_post_event() override;
|
|
virtual Core::EventLoopThreadHandle current_thread_handle() override;
|
|
virtual void wake_thread(Core::EventLoopThreadHandle) override;
|
|
|
|
virtual int register_signal(int, Function<void(int)>) override;
|
|
virtual void unregister_signal(int) override;
|
|
};
|
|
|
|
class EventLoopImplementationMacOS final : public Core::EventLoopImplementation {
|
|
public:
|
|
// FIXME: This currently only manages the main NSApp event loop, as that is all we currently
|
|
// interact with. When we need multiple event loops, or an event loop that isn't the
|
|
// NSApp loop, we will need to create our own CFRunLoop.
|
|
static NonnullOwnPtr<EventLoopImplementationMacOS> create();
|
|
|
|
virtual int exec() override;
|
|
virtual size_t pump(PumpMode) override;
|
|
virtual void quit(int) override;
|
|
virtual void wake() override;
|
|
virtual void deferred_invoke(Function<void()>&&) override;
|
|
virtual bool was_exit_requested() const override;
|
|
|
|
virtual ~EventLoopImplementationMacOS() override;
|
|
|
|
private:
|
|
EventLoopImplementationMacOS();
|
|
|
|
struct Impl;
|
|
NonnullOwnPtr<Impl> m_impl;
|
|
|
|
int m_exit_code { 0 };
|
|
};
|
|
|
|
}
|