summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/FileSystem/Inode.cpp24
-rw-r--r--Kernel/FileSystem/Inode.h9
2 files changed, 13 insertions, 20 deletions
diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp
index 2b0943a238..bab4ade7e5 100644
--- a/Kernel/FileSystem/Inode.cpp
+++ b/Kernel/FileSystem/Inode.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
@@ -22,26 +22,22 @@
namespace Kernel {
-static SpinLock s_all_inodes_lock;
-static Singleton<Inode::List> s_list;
+static Singleton<SpinLockProtectedValue<Inode::AllInstancesList>> s_all_instances;
-static Inode::List& all_with_lock()
+SpinLockProtectedValue<Inode::AllInstancesList>& Inode::all_instances()
{
- VERIFY(s_all_inodes_lock.is_locked());
-
- return *s_list;
+ return s_all_instances;
}
void Inode::sync()
{
NonnullRefPtrVector<Inode, 32> inodes;
- {
- ScopedSpinLock all_inodes_lock(s_all_inodes_lock);
- for (auto& inode : all_with_lock()) {
+ Inode::all_instances().with([&](auto& all_inodes) {
+ for (auto& inode : all_inodes) {
if (inode.is_metadata_dirty())
inodes.append(inode);
}
- }
+ });
for (auto& inode : inodes) {
VERIFY(inode.is_metadata_dirty());
@@ -95,15 +91,11 @@ Inode::Inode(FileSystem& fs, InodeIndex index)
: m_file_system(fs)
, m_index(index)
{
- ScopedSpinLock all_inodes_lock(s_all_inodes_lock);
- all_with_lock().append(*this);
+ Inode::all_instances().with([&](auto& all_inodes) { all_inodes.append(*this); });
}
Inode::~Inode()
{
- ScopedSpinLock all_inodes_lock(s_all_inodes_lock);
- all_with_lock().remove(*this);
-
for (auto& watcher : m_watchers) {
watcher->unregister_by_inode({}, identifier());
}
diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h
index cf77df7507..c2ebbdb7ae 100644
--- a/Kernel/FileSystem/Inode.h
+++ b/Kernel/FileSystem/Inode.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
@@ -10,7 +10,6 @@
#include <AK/Function.h>
#include <AK/HashTable.h>
#include <AK/IntrusiveList.h>
-#include <AK/RefCounted.h>
#include <AK/String.h>
#include <AK/WeakPtr.h>
#include <Kernel/FileSystem/FIFO.h>
@@ -19,11 +18,12 @@
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/Forward.h>
#include <Kernel/KResult.h>
+#include <Kernel/Library/ListedRefCounted.h>
#include <Kernel/Locking/Mutex.h>
namespace Kernel {
-class Inode : public RefCounted<Inode> {
+class Inode : public ListedRefCounted<Inode> {
friend class VirtualFileSystem;
friend class FileSystem;
@@ -134,7 +134,8 @@ private:
Vector<Flock> m_flocks;
public:
- using List = IntrusiveList<Inode, RawPtr<Inode>, &Inode::m_inode_list_node>;
+ using AllInstancesList = IntrusiveList<Inode, RawPtr<Inode>, &Inode::m_inode_list_node>;
+ static SpinLockProtectedValue<Inode::AllInstancesList>& all_instances();
};
}