diff options
author | Andreas Kling <kling@serenityos.org> | 2022-08-21 01:04:35 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-21 12:25:14 +0200 |
commit | 728c3fbd14252bd746f97dbb5441063992074b6b (patch) | |
tree | 539c32ede90702ab3ef35b984addad93769db340 /Kernel/FileSystem/Mount.cpp | |
parent | 5331d243c690c70e431e2f8d260eacab19946c2b (diff) | |
download | serenity-728c3fbd14252bd746f97dbb5441063992074b6b.zip |
Kernel: Use RefPtr instead of LockRefPtr for Custody
By protecting all the RefPtr<Custody> objects that may be accessed from
multiple threads at the same time (with spinlocks), we remove the need
for using LockRefPtr<Custody> (which is basically a RefPtr with a
built-in spinlock.)
Diffstat (limited to 'Kernel/FileSystem/Mount.cpp')
-rw-r--r-- | Kernel/FileSystem/Mount.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/Kernel/FileSystem/Mount.cpp b/Kernel/FileSystem/Mount.cpp index e934d2eb71..733147d746 100644 --- a/Kernel/FileSystem/Mount.cpp +++ b/Kernel/FileSystem/Mount.cpp @@ -14,7 +14,7 @@ namespace Kernel { Mount::Mount(FileSystem& guest_fs, Custody* host_custody, int flags) : m_guest(guest_fs.root_inode()) , m_guest_fs(guest_fs) - , m_host_custody(host_custody) + , m_host_custody(LockRank::None, host_custody) , m_flags(flags) { } @@ -22,30 +22,36 @@ Mount::Mount(FileSystem& guest_fs, Custody* host_custody, int flags) Mount::Mount(Inode& source, Custody& host_custody, int flags) : m_guest(source) , m_guest_fs(source.fs()) - , m_host_custody(host_custody) + , m_host_custody(LockRank::None, host_custody) , m_flags(flags) { } ErrorOr<NonnullOwnPtr<KString>> Mount::absolute_path() const { - if (!m_host_custody) - return KString::try_create("/"sv); - return m_host_custody->try_serialize_absolute_path(); + return m_host_custody.with([&](auto& host_custody) -> ErrorOr<NonnullOwnPtr<KString>> { + if (!host_custody) + return KString::try_create("/"sv); + return host_custody->try_serialize_absolute_path(); + }); } -Inode* Mount::host() +LockRefPtr<Inode> Mount::host() { - if (!m_host_custody) - return nullptr; - return &m_host_custody->inode(); + return m_host_custody.with([](auto& host_custody) -> LockRefPtr<Inode> { + if (!host_custody) + return nullptr; + return &host_custody->inode(); + }); } -Inode const* Mount::host() const +LockRefPtr<Inode const> Mount::host() const { - if (!m_host_custody) - return nullptr; - return &m_host_custody->inode(); + return m_host_custody.with([](auto& host_custody) -> LockRefPtr<Inode const> { + if (!host_custody) + return nullptr; + return &host_custody->inode(); + }); } } |