From 93fceb1890d5eddc3c14e2adbfed6a6ab03f950e Mon Sep 17 00:00:00 2001 From: Liav A Date: Tue, 11 Apr 2023 00:24:47 +0300 Subject: [PATCH] Kernel: Stop using LockRefPtrs in the Jail code Each Jail object within the list is already protected by the global list spinlock, therefore there's no need for using LockRefPtrs at all. --- Kernel/Jail.cpp | 10 +++++----- Kernel/Jail.h | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Kernel/Jail.cpp b/Kernel/Jail.cpp index 3b546ee32b..b0a602afd5 100644 --- a/Kernel/Jail.cpp +++ b/Kernel/Jail.cpp @@ -24,11 +24,11 @@ NonnullRefPtr Jail::process_list() return m_process_list; } -ErrorOr> Jail::create(NonnullOwnPtr name) +ErrorOr> Jail::create(NonnullOwnPtr name) { - return s_all_instances->with([&](auto& list) -> ErrorOr> { + return s_all_instances->with([&](auto& list) -> ErrorOr> { auto process_list = TRY(ProcessList::create()); - auto jail = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) Jail(move(name), generate_jail_id(), move(process_list)))); + auto jail = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Jail(move(name), generate_jail_id(), move(process_list)))); list.append(jail); return jail; }); @@ -50,9 +50,9 @@ ErrorOr Jail::for_each_when_process_is_not_jailed(Function(J }); } -LockRefPtr Jail::find_by_index(JailIndex index) +RefPtr Jail::find_by_index(JailIndex index) { - return s_all_instances->with([&](auto& list) -> LockRefPtr { + return s_all_instances->with([&](auto& list) -> RefPtr { for (auto& jail : list) { if (jail.index() == index) return jail; diff --git a/Kernel/Jail.h b/Kernel/Jail.h index 5258dc27f3..2f8355eccb 100644 --- a/Kernel/Jail.h +++ b/Kernel/Jail.h @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -31,8 +30,8 @@ class Jail : public AtomicRefCounted { public: NonnullRefPtr process_list(); - static LockRefPtr find_by_index(JailIndex); - static ErrorOr> create(NonnullOwnPtr name); + static RefPtr find_by_index(JailIndex); + static ErrorOr> create(NonnullOwnPtr name); static ErrorOr for_each_when_process_is_not_jailed(Function(Jail const&)> callback); StringView name() const { return m_name->view(); } @@ -47,7 +46,7 @@ private: NonnullOwnPtr m_name; JailIndex const m_index; - IntrusiveListNode> m_list_node; + IntrusiveListNode> m_list_node; public: using List = IntrusiveListRelaxedConst<&Jail::m_list_node>;