Files
ladybird/Libraries/LibCore/EventLoopImplementationWindows.h
R-Goc 86b95b1d7a LibCore: Use IOCP for the event loop on Windows
This commit changes the event loop to use IOCPs instead of
WaitForMultipleObjects to wait on events. This is done through the Nt
kernel api NtAssociateWaitCompletionPacket which associates an event
with a completion packet. Each completion packet notifies only once, as
they are normally used to signal completion of an operation so to use
them for notifiers they are associated again after each time they are
triggered.
There are more optimizations that can be done, such as reusing the
EventLoopNotifier and EventLoopTimer structures to reduce the number of
allocations and context switches for timer and notifier registration.
2025-11-07 08:42:43 +01:00

57 lines
1.7 KiB
C++

/*
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullOwnPtr.h>
#include <LibCore/EventLoopImplementation.h>
namespace Core {
class EventLoopManagerWindows final : public EventLoopManager {
public:
virtual ~EventLoopManagerWindows() override = default;
virtual NonnullOwnPtr<EventLoopImplementation> make_implementation() override;
virtual intptr_t register_timer(EventReceiver&, int milliseconds, bool should_reload) override;
virtual void unregister_timer(intptr_t timer_id) override;
virtual void register_notifier(Notifier&) override;
virtual void unregister_notifier(Notifier&) override;
virtual void did_post_event() override;
virtual int register_signal(int signal_number, Function<void(int)> handler) override;
virtual void unregister_signal(int handler_id) override;
};
class EventLoopImplementationWindows final : public EventLoopImplementation {
public:
static NonnullOwnPtr<EventLoopImplementationWindows> create() { return make<EventLoopImplementationWindows>(); }
EventLoopImplementationWindows();
virtual ~EventLoopImplementationWindows() override;
virtual int exec() override;
virtual size_t pump(PumpMode) override;
virtual void quit(int) override;
virtual void wake() override;
virtual bool was_exit_requested() const override { return m_exit_requested; }
virtual void post_event(EventReceiver& receiver, NonnullOwnPtr<Event>&&) override;
private:
bool m_exit_requested { false };
int m_exit_code { 0 };
void const* m_wake_completion_key;
};
using EventLoopManagerPlatform = EventLoopManagerWindows;
}