LibCore: Remove unused NotifierActivationEvent fd() and type() methods

In 11b8bbe one thing that was claimed was that we now properly set the
Notifier's actual fd on the NotifierActivationEvent. It turns out that
claim was false because a crucial step was forgotten: actually set the
m_notifier_fd when registering. Despite that mistake, it ultimately was
irrelevant as the methods on NotifierActivationEvent are currently
unused code. We were posting the event to the correct Notifier receiver
so the on_activation was still getting invoked.

Given they are unused, NotifierActivationEvent can be defined the same
way as TimerEvent is, where we just pass the event type enum to the
Event base class. Additionally, NotificationType can be moved to
the Notifier header as this enum is now always used in the context of
creating or using a Notifier instance.
This commit is contained in:
ayeteadoe 2025-11-21 21:16:47 -08:00 committed by Jelle Raaijmakers
parent c34b5a544e
commit 4fb1ba0193
Notes: github-actions[bot] 2025-11-22 08:48:51 +00:00
7 changed files with 21 additions and 34 deletions

View file

@ -71,32 +71,14 @@ public:
~TimerEvent() = default;
};
enum class NotificationType : u8 {
None = 0,
Read = 1,
Write = 2,
HangUp = 4,
Error = 8,
};
AK_ENUM_BITWISE_OPERATORS(NotificationType);
class NotifierActivationEvent final : public Event {
public:
explicit NotifierActivationEvent(int fd, NotificationType type)
explicit NotifierActivationEvent()
: Event(Event::NotifierActivation)
, m_fd(fd)
, m_type(type)
{
}
~NotifierActivationEvent() = default;
int fd() const { return m_fd; }
NotificationType type() const { return m_type; }
private:
int m_fd;
NotificationType m_type;
};
}

View file

@ -405,7 +405,7 @@ try_select_again:
#ifdef AK_OS_ANDROID
// FIXME: Make the check work under Android, perhaps use ALooper.
ThreadEventQueue::current().post_event(notifier, make<NotifierActivationEvent>(notifier.fd(), notifier.type()));
ThreadEventQueue::current().post_event(notifier, make<NotifierActivationEvent>());
#else
auto revents = thread_data.poll_fds[i].revents;
@ -422,7 +422,7 @@ try_select_again:
type &= notifier.type();
if (type != NotificationType::None)
ThreadEventQueue::current().post_event(notifier, make<NotifierActivationEvent>(notifier.fd(), type));
ThreadEventQueue::current().post_event(notifier, make<NotifierActivationEvent>());
#endif
}
}

View file

@ -96,13 +96,7 @@ struct EventLoopNotifier final : CompletionPacket {
{
}
Notifier::Type notifier_type() const { return m_notifier_type; }
int notifier_fd() const { return m_notifier_fd; }
// These are a space tradeoff for avoiding a double indirection through the notifier*.
Notifier* notifier;
Notifier::Type m_notifier_type;
int m_notifier_fd { -1 };
OwnHandle wait_packet;
OwnHandle wait_event;
};
@ -211,7 +205,7 @@ size_t EventLoopImplementationWindows::pump(PumpMode pump_mode)
}
if (packet->type == CompletionType::Notifer) {
auto* notifier_data = static_cast<EventLoopNotifier*>(packet);
event_queue.post_event(*notifier_data->notifier, make<NotifierActivationEvent>(notifier_data->notifier_fd(), notifier_data->notifier_type()));
event_queue.post_event(*notifier_data->notifier, make<NotifierActivationEvent>());
NTSTATUS status = g_system.NtAssociateWaitCompletionPacket(notifier_data->wait_packet.handle, thread_data->iocp.handle, notifier_data->wait_event.handle, notifier_data, NULL, 0, 0, NULL);
VERIFY(NT_SUCCESS(status));
continue;
@ -279,7 +273,6 @@ void EventLoopManagerWindows::register_notifier(Notifier& notifier)
auto notifier_data = make<EventLoopNotifier>();
notifier_data->type = CompletionType::Notifer;
notifier_data->notifier = &notifier;
notifier_data->m_notifier_type = notifier.type();
notifier_data->wait_event.handle = event;
NTSTATUS status = g_system.NtCreateWaitCompletionPacket(&notifier_data->wait_packet.handle, GENERIC_READ | GENERIC_WRITE, NULL);
VERIFY(NT_SUCCESS(status));

View file

@ -13,6 +13,16 @@
namespace Core {
enum class NotificationType : u8 {
None = 0,
Read = 1,
Write = 2,
HangUp = 4,
Error = 8,
};
AK_ENUM_BITWISE_OPERATORS(NotificationType);
class Notifier final : public EventReceiver {
C_OBJECT(Notifier);

View file

@ -331,7 +331,7 @@ static void socket_notifier(CFSocketRef socket, CFSocketCallBackType notificatio
// before dispatching the event, which allows it to be triggered again.
CFSocketEnableCallBacks(socket, notification_type);
Core::NotifierActivationEvent event(notifier.fd(), notifier.type());
Core::NotifierActivationEvent event;
notifier.dispatch_event(event);
// This manual process of enabling the callbacks also seems to require waking the event loop,

View file

@ -297,7 +297,7 @@ void EventLoopManagerQt::unregister_timer(intptr_t timer_id)
static void qt_notifier_activated(Core::Notifier& notifier)
{
Core::NotifierActivationEvent event(notifier.fd(), notifier.type());
Core::NotifierActivationEvent event;
notifier.dispatch_event(event);
}

View file

@ -221,8 +221,10 @@ static int notifier_callback(int fd, int events, void* data)
if (events & ALOOPER_EVENT_ERROR)
type |= Core::NotificationType::Error;
Core::NotifierActivationEvent event(notifier.fd(), type);
notifier.dispatch_event(event);
if (type != Core::NotificationType::None) {
Core::NotifierActivationEvent event;
notifier.dispatch_event(event);
}
// Wake up from ALooper_pollAll, and service this event on the event queue
current_impl().wake();