From 7bf420d83dc6f3b5a1e0cd2710cad78298056ddf Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Tue, 16 Jul 2019 15:02:22 +0200 Subject: [PATCH] CNotifier: Provide a way to unregister a notifier temporarily --- Libraries/LibCore/CNotifier.cpp | 12 ++++++++++-- Libraries/LibCore/CNotifier.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Libraries/LibCore/CNotifier.cpp b/Libraries/LibCore/CNotifier.cpp index c124191ac1f..d042a579ca0 100644 --- a/Libraries/LibCore/CNotifier.cpp +++ b/Libraries/LibCore/CNotifier.cpp @@ -6,10 +6,18 @@ CNotifier::CNotifier(int fd, unsigned event_mask) : m_fd(fd) , m_event_mask(event_mask) { - CEventLoop::register_notifier({}, *this); + set_enabled(true); } CNotifier::~CNotifier() { - CEventLoop::unregister_notifier({}, *this); + set_enabled(false); +} + +void CNotifier::set_enabled(bool enabled) +{ + if (enabled) + CEventLoop::register_notifier({}, *this); + else + CEventLoop::unregister_notifier({}, *this); } diff --git a/Libraries/LibCore/CNotifier.h b/Libraries/LibCore/CNotifier.h index 196cad8388a..7ef16519148 100644 --- a/Libraries/LibCore/CNotifier.h +++ b/Libraries/LibCore/CNotifier.h @@ -13,6 +13,8 @@ public: CNotifier(int fd, unsigned event_mask); ~CNotifier(); + void set_enabled(bool); + Function on_ready_to_read; Function on_ready_to_write;