From 1fde952c1d75a3afc51f6388e3057de9902662ae Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 21 Dec 2009 20:56:50 +0000 Subject: [PATCH] DefaultNotificationService: * Added Lock()/Unlock() for explicit locking by a service user. * Added NotifyLocked() and made Notify() inline. * Added HasListeners() so one can check whether there is a listener at all before preparing the event message. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34736 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/Notifications.h | 21 ++++++++++++++++++++- src/system/kernel/Notifications.cpp | 4 +--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/headers/private/kernel/Notifications.h b/headers/private/kernel/Notifications.h index ca6f9f08d2..a5a8686f46 100644 --- a/headers/private/kernel/Notifications.h +++ b/headers/private/kernel/Notifications.h @@ -131,8 +131,18 @@ public: DefaultNotificationService(const char* name); virtual ~DefaultNotificationService(); - void Notify(const KMessage& event, uint32 eventMask); + inline bool Lock() + { return recursive_lock_lock(&fLock) + == B_OK; } + inline void Unlock() + { recursive_lock_unlock(&fLock); } + inline void Notify(const KMessage& event, uint32 eventMask); + void NotifyLocked(const KMessage& event, + uint32 eventMask); + + inline bool HasListeners() const + { return !fListeners.IsEmpty(); } virtual status_t AddListener(const KMessage* eventSpecifier, NotificationListener& listener); virtual status_t UpdateListener(const KMessage* eventSpecifier, @@ -238,6 +248,15 @@ private: ServiceHash fServiceHash; }; + +void +DefaultNotificationService::Notify(const KMessage& event, uint32 eventMask) +{ + RecursiveLocker _(fLock); + NotifyLocked(event, eventMask); +} + + extern "C" { #endif // __cplusplus diff --git a/src/system/kernel/Notifications.cpp b/src/system/kernel/Notifications.cpp index d9c36b63ce..8ffb62198e 100644 --- a/src/system/kernel/Notifications.cpp +++ b/src/system/kernel/Notifications.cpp @@ -173,10 +173,8 @@ DefaultNotificationService::~DefaultNotificationService() common bit with this mask will receive the event. */ void -DefaultNotificationService::Notify(const KMessage& event, uint32 eventMask) +DefaultNotificationService::NotifyLocked(const KMessage& event, uint32 eventMask) { - RecursiveLocker _(fLock); - // Note: The following iterations support that the listener removes itself // in the hook method. That's a property of the DoublyLinkedList iterator.