Parcourir la source

Kernel: Migrate FIFO table locking to ProtectedValue

Jean-Baptiste Boric il y a 4 ans
Parent
commit
6d83b2d8f0
1 fichiers modifiés avec 9 ajouts et 7 suppressions
  1. 9 7
      Kernel/FileSystem/FIFO.cpp

+ 9 - 7
Kernel/FileSystem/FIFO.cpp

@@ -10,16 +10,16 @@
 #include <AK/StdLibExtras.h>
 #include <Kernel/FileSystem/FIFO.h>
 #include <Kernel/FileSystem/FileDescription.h>
-#include <Kernel/Locking/Lockable.h>
 #include <Kernel/Locking/Mutex.h>
+#include <Kernel/Locking/ProtectedValue.h>
 #include <Kernel/Process.h>
 #include <Kernel/Thread.h>
 
 namespace Kernel {
 
-static AK::Singleton<Lockable<HashTable<FIFO*>>> s_table;
+static AK::Singleton<ProtectedValue<HashTable<FIFO*>>> s_table;
 
-static Lockable<HashTable<FIFO*>>& all_fifos()
+static ProtectedValue<HashTable<FIFO*>>& all_fifos()
 {
     return *s_table;
 }
@@ -79,8 +79,9 @@ FIFO::FIFO(uid_t uid, NonnullOwnPtr<DoubleBuffer> buffer)
     : m_buffer(move(buffer))
     , m_uid(uid)
 {
-    MutexLocker locker(all_fifos().lock());
-    all_fifos().resource().set(this);
+    all_fifos().with_exclusive([&](auto& table) {
+        table.set(this);
+    });
     m_fifo_id = ++s_next_fifo_id;
 
     // Use the same block condition for read and write
@@ -91,8 +92,9 @@ FIFO::FIFO(uid_t uid, NonnullOwnPtr<DoubleBuffer> buffer)
 
 FIFO::~FIFO()
 {
-    MutexLocker locker(all_fifos().lock());
-    all_fifos().resource().remove(this);
+    all_fifos().with_exclusive([&](auto& table) {
+        table.remove(this);
+    });
 }
 
 void FIFO::attach(Direction direction)