1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:58:11 +00:00

Kernel: Protect the Custody cache with a mutex instead of a spinlock

We don't need to access the Custody cache in IRQs or anything like that,
so it should be fine to use a regular Mutex (via ProtectedValue.)

This allows threads to block while waiting for the custody cache.
Thanks to Sergey for pointing this out. :^)
This commit is contained in:
Andreas Kling 2021-08-18 00:43:16 +02:00
parent 8ad42e6771
commit c70e2f2519

View file

@ -10,20 +10,20 @@
#include <AK/Vector.h>
#include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/Locking/SpinLockProtectedValue.h>
#include <Kernel/Locking/ProtectedValue.h>
namespace Kernel {
static Singleton<SpinLockProtectedValue<Custody::AllCustodiesList>> s_all_custodies;
static Singleton<ProtectedValue<Custody::AllCustodiesList>> s_all_custodies;
static SpinLockProtectedValue<Custody::AllCustodiesList>& all_custodies()
static ProtectedValue<Custody::AllCustodiesList>& all_custodies()
{
return s_all_custodies;
}
KResultOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringView name, Inode& inode, int mount_flags)
{
return all_custodies().with([&](auto& all_custodies) -> KResultOr<NonnullRefPtr<Custody>> {
return all_custodies().with_exclusive([&](auto& all_custodies) -> KResultOr<NonnullRefPtr<Custody>> {
for (Custody& custody : all_custodies) {
if (custody.parent() == parent
&& custody.name() == name
@ -47,7 +47,7 @@ KResultOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringVie
bool Custody::unref() const
{
bool should_destroy = all_custodies().with([&](auto&) {
bool should_destroy = all_custodies().with_exclusive([&](auto&) {
if (deref_base())
return false;
m_all_custodies_list_node.remove();