Author: bonefish Date: 2009-12-21 21:56:50 +0100 (Mon, 21 Dec 2009) New Revision: 34736 Changeset: http://dev.haiku-os.org/changeset/34736/haiku Modified: haiku/trunk/headers/private/kernel/Notifications.h haiku/trunk/src/system/kernel/Notifications.cpp Log: 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. Modified: haiku/trunk/headers/private/kernel/Notifications.h =================================================================== --- haiku/trunk/headers/private/kernel/Notifications.h 2009-12-21 19:59:13 UTC (rev 34735) +++ haiku/trunk/headers/private/kernel/Notifications.h 2009-12-21 20:56:50 UTC (rev 34736) @@ -131,8 +131,18 @@ 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 @@ ServiceHash fServiceHash; }; + +void +DefaultNotificationService::Notify(const KMessage& event, uint32 eventMask) +{ + RecursiveLocker _(fLock); + NotifyLocked(event, eventMask); +} + + extern "C" { #endif // __cplusplus Modified: haiku/trunk/src/system/kernel/Notifications.cpp =================================================================== --- haiku/trunk/src/system/kernel/Notifications.cpp 2009-12-21 19:59:13 UTC (rev 34735) +++ haiku/trunk/src/system/kernel/Notifications.cpp 2009-12-21 20:56:50 UTC (rev 34736) @@ -173,10 +173,8 @@ 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.