From 5ac03c3714773ef7de9b630d42633d366a545630 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 16 Jan 2025 23:23:19 -0500 Subject: [PATCH] ramfs: Clean up Iterator lockers API. No functional change intended. --- .../file_systems/ramfs/AttributeIterator.cpp | 6 ++--- .../kernel/file_systems/ramfs/Directory.cpp | 4 ++-- .../file_systems/ramfs/EntryIterator.cpp | 14 ++++++----- .../kernel/file_systems/ramfs/Node.cpp | 2 +- .../kernel/file_systems/ramfs/Volume.cpp | 23 ++++--------------- .../kernel/file_systems/ramfs/Volume.h | 10 ++++---- 6 files changed, 22 insertions(+), 37 deletions(-) diff --git a/src/add-ons/kernel/file_systems/ramfs/AttributeIterator.cpp b/src/add-ons/kernel/file_systems/ramfs/AttributeIterator.cpp index 65d25827eb..4a0ec1d890 100644 --- a/src/add-ons/kernel/file_systems/ramfs/AttributeIterator.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/AttributeIterator.cpp @@ -64,7 +64,7 @@ AttributeIterator::Suspend() if (fNode == NULL) return B_ERROR; - RecursiveLocker locker(fNode->GetVolume()->AttributeIteratorLocker()); + RecursiveLocker locker(fNode->GetVolume()->GetAttributeIteratorLock()); if (!locker.IsLocked()) return B_ERROR; @@ -85,7 +85,7 @@ AttributeIterator::Resume() if (fNode == NULL) return B_ERROR; - RecursiveLocker locker(fNode->GetVolume()->AttributeIteratorLocker()); + RecursiveLocker locker(fNode->GetVolume()->GetAttributeIteratorLock()); if (!locker.IsLocked()) return B_ERROR; @@ -127,7 +127,7 @@ AttributeIterator::Rewind() if (fNode == NULL) return B_ERROR; - RecursiveLocker locker(fNode->GetVolume()->AttributeIteratorLocker()); + RecursiveLocker locker(fNode->GetVolume()->GetAttributeIteratorLock()); if (!locker.IsLocked()) return B_ERROR; diff --git a/src/add-ons/kernel/file_systems/ramfs/Directory.cpp b/src/add-ons/kernel/file_systems/ramfs/Directory.cpp index cb1fa46374..9c8d17e830 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Directory.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/Directory.cpp @@ -190,7 +190,7 @@ Directory::RemoveEntry(Entry *entry) : B_BAD_VALUE); if (error == B_OK) { // move all iterators pointing to the entry to the next entry - if (GetVolume()->IteratorLock()) { + if (recursive_lock_lock(&GetVolume()->GetIteratorLock()) == B_OK) { // set the iterators' current entry Entry *nextEntry = fEntries.GetNext(entry); DoublyLinkedList *iterators @@ -208,7 +208,7 @@ Directory::RemoveEntry(Entry *entry) nextIterators->TakeFrom(iterators); } else iterators->RemoveAll(); - GetVolume()->IteratorUnlock(); + recursive_lock_unlock(&GetVolume()->GetIteratorLock()); } else error = B_ERROR; // remove the entry diff --git a/src/add-ons/kernel/file_systems/ramfs/EntryIterator.cpp b/src/add-ons/kernel/file_systems/ramfs/EntryIterator.cpp index 948322bcc0..a046eea3df 100644 --- a/src/add-ons/kernel/file_systems/ramfs/EntryIterator.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/EntryIterator.cpp @@ -8,6 +8,8 @@ #include "EntryIterator.h" #include "Volume.h" +#include + EntryIterator::EntryIterator(Directory *directory) : @@ -65,10 +67,10 @@ EntryIterator::Suspend() return B_ERROR; if (fEntry != NULL) { - if (!fDirectory->GetVolume()->IteratorLock()) + RecursiveLocker locker(fDirectory->GetVolume()->GetIteratorLock()); + if (!locker.IsLocked()) return B_ERROR; fEntry->AttachEntryIterator(this); - fDirectory->GetVolume()->IteratorUnlock(); } fSuspended = true; @@ -83,10 +85,10 @@ EntryIterator::Resume() return B_ERROR; if (fSuspended && fEntry != NULL) { - if (!fDirectory->GetVolume()->IteratorLock()) + RecursiveLocker locker(fDirectory->GetVolume()->GetIteratorLock()); + if (!locker.IsLocked()) return B_ERROR; fEntry->DetachEntryIterator(this); - fDirectory->GetVolume()->IteratorUnlock(); } fSuspended = false; @@ -121,7 +123,8 @@ EntryIterator::Rewind() if (fDirectory == NULL) return B_ERROR; - if (!fDirectory->GetVolume()->IteratorLock()) + RecursiveLocker locker(fDirectory->GetVolume()->GetIteratorLock()); + if (!locker.IsLocked()) return B_ERROR; if (fSuspended && fEntry != NULL) @@ -130,7 +133,6 @@ EntryIterator::Rewind() fEntry = NULL; fIsNext = false; fDone = false; - fDirectory->GetVolume()->IteratorUnlock(); return B_OK; } diff --git a/src/add-ons/kernel/file_systems/ramfs/Node.cpp b/src/add-ons/kernel/file_systems/ramfs/Node.cpp index 5b756af02c..2b11014274 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Node.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/Node.cpp @@ -198,7 +198,7 @@ Node::RemoveAttribute(Attribute *attribute) if (attribute == NULL || attribute->GetNode() != this) return B_BAD_VALUE; - RecursiveLocker locker(GetVolume()->AttributeIteratorLocker()); + RecursiveLocker locker(GetVolume()->GetAttributeIteratorLock()); if (!locker.IsLocked()) return B_ERROR; diff --git a/src/add-ons/kernel/file_systems/ramfs/Volume.cpp b/src/add-ons/kernel/file_systems/ramfs/Volume.cpp index 45943e7004..87b41ef2c3 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/Volume.cpp @@ -140,8 +140,8 @@ Volume::Volume(fs_volume* volume) fMounted(false) { rw_lock_init(&fLocker, "ramfs volume"); - recursive_lock_init(&fIteratorLocker, "ramfs iterators"); - recursive_lock_init(&fAttributeIteratorLocker, "ramfs attribute iterators"); + recursive_lock_init(&fIteratorLock, "ramfs iterators"); + recursive_lock_init(&fAttributeIteratorLock, "ramfs attribute iterators"); recursive_lock_init(&fQueryLocker, "ramfs queries"); } @@ -150,14 +150,13 @@ Volume::~Volume() { Unmount(); - recursive_lock_destroy(&fAttributeIteratorLocker); - recursive_lock_destroy(&fIteratorLocker); + recursive_lock_destroy(&fAttributeIteratorLock); + recursive_lock_destroy(&fIteratorLock); recursive_lock_destroy(&fQueryLocker); rw_lock_destroy(&fLocker); } - status_t Volume::Mount(uint32 flags) { @@ -765,17 +764,3 @@ Volume::WriteUnlock() { rw_lock_write_unlock(&fLocker); } - - -bool -Volume::IteratorLock() -{ - return recursive_lock_lock(&fIteratorLocker) == B_OK; -} - - -void -Volume::IteratorUnlock() -{ - recursive_lock_unlock(&fIteratorLocker); -} diff --git a/src/add-ons/kernel/file_systems/ramfs/Volume.h b/src/add-ons/kernel/file_systems/ramfs/Volume.h index 93ffb36814..ada3b4c6be 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Volume.h +++ b/src/add-ons/kernel/file_systems/ramfs/Volume.h @@ -165,10 +165,8 @@ public: void WriteUnlock(); inline void AssertWriteLocked() { ASSERT_WRITE_LOCKED_RW_LOCK(&fLocker); } - bool IteratorLock(); - void IteratorUnlock(); - - recursive_lock& AttributeIteratorLocker() { return fAttributeIteratorLocker; } + recursive_lock& GetIteratorLock() { return fIteratorLock; } + recursive_lock& GetAttributeIteratorLock() { return fAttributeIteratorLock; } protected: fs_volume* fVolume; @@ -188,8 +186,8 @@ private: EntryListenerTree *fEntryListeners; EntryListenerList fAnyEntryListeners; - recursive_lock fIteratorLocker; - recursive_lock fAttributeIteratorLocker; + recursive_lock fIteratorLock; + recursive_lock fAttributeIteratorLock; recursive_lock fQueryLocker; QueryList fQueries;