Quellcode durchsuchen

Kernel: Protect the Custody cache with a spinlock

Protecting it with a mutex meant that anyone unref()'ing a Custody
might need to block on said mutex.
Andreas Kling vor 2 Jahren
Ursprung
Commit
cb04caa18e
2 geänderte Dateien mit 8 neuen und 8 gelöschten Zeilen
  1. 4 4
      Kernel/FileSystem/Custody.cpp
  2. 4 4
      Kernel/FileSystem/Custody.h

+ 4 - 4
Kernel/FileSystem/Custody.cpp

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -13,16 +13,16 @@
 
 namespace Kernel {
 
-static Singleton<MutexProtected<Custody::AllCustodiesList>> s_all_instances;
+static Singleton<SpinlockProtected<Custody::AllCustodiesList>> s_all_instances;
 
-MutexProtected<Custody::AllCustodiesList>& Custody::all_instances()
+SpinlockProtected<Custody::AllCustodiesList>& Custody::all_instances()
 {
     return s_all_instances;
 }
 
 ErrorOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringView name, Inode& inode, int mount_flags)
 {
-    return all_instances().with_exclusive([&](auto& all_custodies) -> ErrorOr<NonnullRefPtr<Custody>> {
+    return all_instances().with([&](auto& all_custodies) -> ErrorOr<NonnullRefPtr<Custody>> {
         for (Custody& custody : all_custodies) {
             if (custody.parent() == parent
                 && custody.name() == name

+ 4 - 4
Kernel/FileSystem/Custody.h

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -12,11 +12,11 @@
 #include <Kernel/Forward.h>
 #include <Kernel/KString.h>
 #include <Kernel/Library/ListedRefCounted.h>
-#include <Kernel/Locking/MutexProtected.h>
+#include <Kernel/Locking/SpinlockProtected.h>
 
 namespace Kernel {
 
-class Custody : public ListedRefCounted<Custody, LockType::Mutex> {
+class Custody : public ListedRefCounted<Custody, LockType::Spinlock> {
 public:
     static ErrorOr<NonnullRefPtr<Custody>> try_create(Custody* parent, StringView name, Inode&, int mount_flags);
 
@@ -44,7 +44,7 @@ private:
 
 public:
     using AllCustodiesList = IntrusiveList<&Custody::m_all_custodies_list_node>;
-    static MutexProtected<Custody::AllCustodiesList>& all_instances();
+    static SpinlockProtected<Custody::AllCustodiesList>& all_instances();
 };
 
 }