From 038d9b44d15afc0e356382cf379dc1b42761c7f4 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 13 Dec 2024 17:17:43 -0500 Subject: [PATCH] kernel/listeners: Use an rw_spinlock for the gWaitObjectListenerLock. When the system profiler is in use, this spinlock is used very often. Internally there's another spinlock which isn't (yet) rw, though. --- headers/private/kernel/listeners.h | 6 +++--- src/system/kernel/debug/system_profiler.cpp | 4 ++-- src/system/kernel/listeners.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/headers/private/kernel/listeners.h b/headers/private/kernel/listeners.h index 6406435325..4db1d5b4c0 100644 --- a/headers/private/kernel/listeners.h +++ b/headers/private/kernel/listeners.h @@ -80,7 +80,7 @@ struct WaitObjectListener : DoublyLinkedListLinkImpl { typedef DoublyLinkedList WaitObjectListenerList; extern WaitObjectListenerList gWaitObjectListeners; -extern spinlock gWaitObjectListenerLock; +extern rw_spinlock gWaitObjectListenerLock; template @@ -89,7 +89,7 @@ NotifyWaitObjectListeners(void (WaitObjectListener::*hook)(Parameter1), Parameter1 parameter1) { if (!gWaitObjectListeners.IsEmpty()) { - InterruptsSpinLocker locker(gWaitObjectListenerLock); + InterruptsReadSpinLocker locker(gWaitObjectListenerLock); WaitObjectListenerList::Iterator it = gWaitObjectListeners.GetIterator(); while (WaitObjectListener* listener = it.Next()) @@ -105,7 +105,7 @@ NotifyWaitObjectListeners( Parameter1 parameter1, Parameter2 parameter2) { if (!gWaitObjectListeners.IsEmpty()) { - InterruptsSpinLocker locker(gWaitObjectListenerLock); + InterruptsReadSpinLocker locker(gWaitObjectListenerLock); WaitObjectListenerList::Iterator it = gWaitObjectListeners.GetIterator(); while (WaitObjectListener* listener = it.Next()) diff --git a/src/system/kernel/debug/system_profiler.cpp b/src/system/kernel/debug/system_profiler.cpp index 431d7ab553..3e94c79263 100644 --- a/src/system/kernel/debug/system_profiler.cpp +++ b/src/system/kernel/debug/system_profiler.cpp @@ -321,7 +321,7 @@ SystemProfiler::~SystemProfiler() // stop wait object listening if (fWaitObjectNotificationsRequested) { - InterruptsSpinLocker locker(gWaitObjectListenerLock); + InterruptsWriteSpinLocker locker(gWaitObjectListenerLock); remove_wait_object_listener(this); } @@ -514,7 +514,7 @@ SystemProfiler::Init() scheduler_add_listener(this); fSchedulerNotificationsRequested = true; - InterruptsSpinLocker waitObjectLocker(gWaitObjectListenerLock); + InterruptsWriteSpinLocker waitObjectLocker(gWaitObjectListenerLock); add_wait_object_listener(this); fWaitObjectNotificationsRequested = true; waitObjectLocker.Unlock(); diff --git a/src/system/kernel/listeners.cpp b/src/system/kernel/listeners.cpp index 61941ff120..0fd752d116 100644 --- a/src/system/kernel/listeners.cpp +++ b/src/system/kernel/listeners.cpp @@ -7,7 +7,7 @@ WaitObjectListenerList gWaitObjectListeners; -spinlock gWaitObjectListenerLock = B_SPINLOCK_INITIALIZER; +rw_spinlock gWaitObjectListenerLock = B_RW_SPINLOCK_INITIALIZER; WaitObjectListener::~WaitObjectListener()