From cce39b3cc0fadcf313085a9229de51a218556bdf Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 17 Jan 2025 00:13:43 -0500 Subject: [PATCH] ramfs: Add lock for NodeListeners. This is only needed on add/remove; when the lists are actually iterated we should already have a write lock. --- src/add-ons/kernel/file_systems/ramfs/Volume.cpp | 10 ++++++++++ src/add-ons/kernel/file_systems/ramfs/Volume.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/add-ons/kernel/file_systems/ramfs/Volume.cpp b/src/add-ons/kernel/file_systems/ramfs/Volume.cpp index 87b41ef2c3..04b9d0c917 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/Volume.cpp @@ -140,6 +140,7 @@ Volume::Volume(fs_volume* volume) fMounted(false) { rw_lock_init(&fLocker, "ramfs volume"); + recursive_lock_init(&fListenersLock, "ramfs listeners"); recursive_lock_init(&fIteratorLock, "ramfs iterators"); recursive_lock_init(&fAttributeIteratorLock, "ramfs attribute iterators"); recursive_lock_init(&fQueryLocker, "ramfs queries"); @@ -153,6 +154,7 @@ Volume::~Volume() recursive_lock_destroy(&fAttributeIteratorLock); recursive_lock_destroy(&fIteratorLock); recursive_lock_destroy(&fQueryLocker); + recursive_lock_destroy(&fListenersLock); rw_lock_destroy(&fLocker); } @@ -461,7 +463,9 @@ Volume::AddNodeListener(NodeListener *listener, Node *node, uint32 flags) || !(flags & NODE_LISTEN_ALL)) { return B_BAD_VALUE; } + // add the listener to the right container + RecursiveLocker locker(fListenersLock); status_t error = B_OK; NodeListenerValue value(listener, node, flags); if (flags & NODE_LISTEN_ANY_NODE) { @@ -478,6 +482,8 @@ Volume::RemoveNodeListener(NodeListener *listener, Node *node) { if (!listener) return B_BAD_VALUE; + + RecursiveLocker locker(fListenersLock); status_t error = B_OK; if (node) error = fNodeListeners->Remove(node, listener); @@ -573,7 +579,9 @@ Volume::AddEntryListener(EntryListener *listener, Entry *entry, uint32 flags) || !(flags & ENTRY_LISTEN_ALL)) { return B_BAD_VALUE; } + // add the listener to the right container + RecursiveLocker locker(fListenersLock); status_t error = B_OK; EntryListenerValue value(listener, entry, flags); if (flags & ENTRY_LISTEN_ANY_ENTRY) { @@ -590,6 +598,8 @@ Volume::RemoveEntryListener(EntryListener *listener, Entry *entry) { if (!listener) return B_BAD_VALUE; + + RecursiveLocker locker(fListenersLock); status_t error = B_OK; if (entry) error = fEntryListeners->Remove(entry, listener); diff --git a/src/add-ons/kernel/file_systems/ramfs/Volume.h b/src/add-ons/kernel/file_systems/ramfs/Volume.h index ada3b4c6be..42de6c0bf4 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Volume.h +++ b/src/add-ons/kernel/file_systems/ramfs/Volume.h @@ -181,6 +181,8 @@ private: DirectoryEntryTable *fDirectoryEntryTable; IndexDirectory *fIndexDirectory; Directory *fRootDirectory; + + recursive_lock fListenersLock; NodeListenerTree *fNodeListeners; NodeListenerList fAnyNodeListeners; EntryListenerTree *fEntryListeners;