ramfs: Clean up Iterator lockers API.

No functional change intended.
This commit is contained in:
Augustin Cavalier 2025-01-16 23:23:19 -05:00
parent c9892ac20f
commit 5ac03c3714
6 changed files with 22 additions and 37 deletions

View File

@ -64,7 +64,7 @@ AttributeIterator::Suspend()
if (fNode == NULL) if (fNode == NULL)
return B_ERROR; return B_ERROR;
RecursiveLocker locker(fNode->GetVolume()->AttributeIteratorLocker()); RecursiveLocker locker(fNode->GetVolume()->GetAttributeIteratorLock());
if (!locker.IsLocked()) if (!locker.IsLocked())
return B_ERROR; return B_ERROR;
@ -85,7 +85,7 @@ AttributeIterator::Resume()
if (fNode == NULL) if (fNode == NULL)
return B_ERROR; return B_ERROR;
RecursiveLocker locker(fNode->GetVolume()->AttributeIteratorLocker()); RecursiveLocker locker(fNode->GetVolume()->GetAttributeIteratorLock());
if (!locker.IsLocked()) if (!locker.IsLocked())
return B_ERROR; return B_ERROR;
@ -127,7 +127,7 @@ AttributeIterator::Rewind()
if (fNode == NULL) if (fNode == NULL)
return B_ERROR; return B_ERROR;
RecursiveLocker locker(fNode->GetVolume()->AttributeIteratorLocker()); RecursiveLocker locker(fNode->GetVolume()->GetAttributeIteratorLock());
if (!locker.IsLocked()) if (!locker.IsLocked())
return B_ERROR; return B_ERROR;

View File

@ -190,7 +190,7 @@ Directory::RemoveEntry(Entry *entry)
: B_BAD_VALUE); : B_BAD_VALUE);
if (error == B_OK) { if (error == B_OK) {
// move all iterators pointing to the entry to the next entry // 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 // set the iterators' current entry
Entry *nextEntry = fEntries.GetNext(entry); Entry *nextEntry = fEntries.GetNext(entry);
DoublyLinkedList<EntryIterator> *iterators DoublyLinkedList<EntryIterator> *iterators
@ -208,7 +208,7 @@ Directory::RemoveEntry(Entry *entry)
nextIterators->TakeFrom(iterators); nextIterators->TakeFrom(iterators);
} else } else
iterators->RemoveAll(); iterators->RemoveAll();
GetVolume()->IteratorUnlock(); recursive_lock_unlock(&GetVolume()->GetIteratorLock());
} else } else
error = B_ERROR; error = B_ERROR;
// remove the entry // remove the entry

View File

@ -8,6 +8,8 @@
#include "EntryIterator.h" #include "EntryIterator.h"
#include "Volume.h" #include "Volume.h"
#include <util/AutoLock.h>
EntryIterator::EntryIterator(Directory *directory) EntryIterator::EntryIterator(Directory *directory)
: :
@ -65,10 +67,10 @@ EntryIterator::Suspend()
return B_ERROR; return B_ERROR;
if (fEntry != NULL) { if (fEntry != NULL) {
if (!fDirectory->GetVolume()->IteratorLock()) RecursiveLocker locker(fDirectory->GetVolume()->GetIteratorLock());
if (!locker.IsLocked())
return B_ERROR; return B_ERROR;
fEntry->AttachEntryIterator(this); fEntry->AttachEntryIterator(this);
fDirectory->GetVolume()->IteratorUnlock();
} }
fSuspended = true; fSuspended = true;
@ -83,10 +85,10 @@ EntryIterator::Resume()
return B_ERROR; return B_ERROR;
if (fSuspended && fEntry != NULL) { if (fSuspended && fEntry != NULL) {
if (!fDirectory->GetVolume()->IteratorLock()) RecursiveLocker locker(fDirectory->GetVolume()->GetIteratorLock());
if (!locker.IsLocked())
return B_ERROR; return B_ERROR;
fEntry->DetachEntryIterator(this); fEntry->DetachEntryIterator(this);
fDirectory->GetVolume()->IteratorUnlock();
} }
fSuspended = false; fSuspended = false;
@ -121,7 +123,8 @@ EntryIterator::Rewind()
if (fDirectory == NULL) if (fDirectory == NULL)
return B_ERROR; return B_ERROR;
if (!fDirectory->GetVolume()->IteratorLock()) RecursiveLocker locker(fDirectory->GetVolume()->GetIteratorLock());
if (!locker.IsLocked())
return B_ERROR; return B_ERROR;
if (fSuspended && fEntry != NULL) if (fSuspended && fEntry != NULL)
@ -130,7 +133,6 @@ EntryIterator::Rewind()
fEntry = NULL; fEntry = NULL;
fIsNext = false; fIsNext = false;
fDone = false; fDone = false;
fDirectory->GetVolume()->IteratorUnlock();
return B_OK; return B_OK;
} }

View File

@ -198,7 +198,7 @@ Node::RemoveAttribute(Attribute *attribute)
if (attribute == NULL || attribute->GetNode() != this) if (attribute == NULL || attribute->GetNode() != this)
return B_BAD_VALUE; return B_BAD_VALUE;
RecursiveLocker locker(GetVolume()->AttributeIteratorLocker()); RecursiveLocker locker(GetVolume()->GetAttributeIteratorLock());
if (!locker.IsLocked()) if (!locker.IsLocked())
return B_ERROR; return B_ERROR;

View File

@ -140,8 +140,8 @@ Volume::Volume(fs_volume* volume)
fMounted(false) fMounted(false)
{ {
rw_lock_init(&fLocker, "ramfs volume"); rw_lock_init(&fLocker, "ramfs volume");
recursive_lock_init(&fIteratorLocker, "ramfs iterators"); recursive_lock_init(&fIteratorLock, "ramfs iterators");
recursive_lock_init(&fAttributeIteratorLocker, "ramfs attribute iterators"); recursive_lock_init(&fAttributeIteratorLock, "ramfs attribute iterators");
recursive_lock_init(&fQueryLocker, "ramfs queries"); recursive_lock_init(&fQueryLocker, "ramfs queries");
} }
@ -150,14 +150,13 @@ Volume::~Volume()
{ {
Unmount(); Unmount();
recursive_lock_destroy(&fAttributeIteratorLocker); recursive_lock_destroy(&fAttributeIteratorLock);
recursive_lock_destroy(&fIteratorLocker); recursive_lock_destroy(&fIteratorLock);
recursive_lock_destroy(&fQueryLocker); recursive_lock_destroy(&fQueryLocker);
rw_lock_destroy(&fLocker); rw_lock_destroy(&fLocker);
} }
status_t status_t
Volume::Mount(uint32 flags) Volume::Mount(uint32 flags)
{ {
@ -765,17 +764,3 @@ Volume::WriteUnlock()
{ {
rw_lock_write_unlock(&fLocker); rw_lock_write_unlock(&fLocker);
} }
bool
Volume::IteratorLock()
{
return recursive_lock_lock(&fIteratorLocker) == B_OK;
}
void
Volume::IteratorUnlock()
{
recursive_lock_unlock(&fIteratorLocker);
}

View File

@ -165,10 +165,8 @@ public:
void WriteUnlock(); void WriteUnlock();
inline void AssertWriteLocked() { ASSERT_WRITE_LOCKED_RW_LOCK(&fLocker); } inline void AssertWriteLocked() { ASSERT_WRITE_LOCKED_RW_LOCK(&fLocker); }
bool IteratorLock(); recursive_lock& GetIteratorLock() { return fIteratorLock; }
void IteratorUnlock(); recursive_lock& GetAttributeIteratorLock() { return fAttributeIteratorLock; }
recursive_lock& AttributeIteratorLocker() { return fAttributeIteratorLocker; }
protected: protected:
fs_volume* fVolume; fs_volume* fVolume;
@ -188,8 +186,8 @@ private:
EntryListenerTree *fEntryListeners; EntryListenerTree *fEntryListeners;
EntryListenerList fAnyEntryListeners; EntryListenerList fAnyEntryListeners;
recursive_lock fIteratorLocker; recursive_lock fIteratorLock;
recursive_lock fAttributeIteratorLocker; recursive_lock fAttributeIteratorLock;
recursive_lock fQueryLocker; recursive_lock fQueryLocker;
QueryList fQueries; QueryList fQueries;