From 89dd4ee819a7b48e22a42bfe2c9cfa065fb4237d Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 14 Jan 2025 21:37:43 -0500 Subject: [PATCH] ramfs: Avoid acquiring locks for suspend/resume of EntryIterator in more cases. If we don't have an Entry to attach/detach from, then we don't need to acquire any locks at all. Now that we return multiple dirents from read_dir, it's much more likely that we wind up with EntryIterators in such a state, so this avoids some lock contention. --- .../file_systems/ramfs/EntryIterator.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/add-ons/kernel/file_systems/ramfs/EntryIterator.cpp b/src/add-ons/kernel/file_systems/ramfs/EntryIterator.cpp index 2ebe1df4af..948322bcc0 100644 --- a/src/add-ons/kernel/file_systems/ramfs/EntryIterator.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/EntryIterator.cpp @@ -64,13 +64,13 @@ EntryIterator::Suspend() if (fDirectory == NULL || fSuspended) return B_ERROR; - if (!fDirectory->GetVolume()->IteratorLock()) - return B_ERROR; - - if (fEntry != NULL) + if (fEntry != NULL) { + if (!fDirectory->GetVolume()->IteratorLock()) + return B_ERROR; fEntry->AttachEntryIterator(this); + fDirectory->GetVolume()->IteratorUnlock(); + } - fDirectory->GetVolume()->IteratorUnlock(); fSuspended = true; return B_OK; } @@ -82,14 +82,14 @@ EntryIterator::Resume() if (fDirectory == NULL) return B_ERROR; - if (!fDirectory->GetVolume()->IteratorLock()) - return B_ERROR; - - if (fSuspended && fEntry != NULL) + if (fSuspended && fEntry != NULL) { + if (!fDirectory->GetVolume()->IteratorLock()) + return B_ERROR; fEntry->DetachEntryIterator(this); + fDirectory->GetVolume()->IteratorUnlock(); + } fSuspended = false; - fDirectory->GetVolume()->IteratorUnlock(); return B_OK; }