ladybird/Libraries/LibCore/Notifier.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

48 lines
957 B
C++

/*
* Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Function.h>
#include <LibCore/Event.h>
#include <LibCore/EventReceiver.h>
#include <pthread.h>
namespace Core {
class Notifier final : public EventReceiver {
C_OBJECT(Notifier);
public:
using Type = NotificationType;
virtual ~Notifier() override;
void set_enabled(bool);
Function<void()> on_activation;
void close();
int fd() const { return m_fd; }
Type type() const { return m_type; }
void set_type(Type type);
void event(Core::Event&) override;
void set_owner_thread(pthread_t owner_thread) { m_owner_thread = owner_thread; }
pthread_t owner_thread() const { return m_owner_thread; }
private:
Notifier(int fd, Type type);
pthread_t m_owner_thread {};
int m_fd { -1 };
Type m_type { Type::None };
bool m_is_enabled { false };
};
}