mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
Kernel: Port Custody to ListedRefCounted
Custody's unref is one of many implementions of ListedRefCounted's behaviour in the Kernel, which results in avoidable bugs caused by the fragmentation of the implementations. This commit starts the work of replacing all custom implementations with ListedRefCounted by porting Custody to it.
This commit is contained in:
parent
be91b4fe3e
commit
81e23617d6
Notes:
sideshowbarker
2024-07-17 22:01:17 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/81e23617d65 Pull-request: https://github.com/SerenityOS/serenity/pull/11474 Reviewed-by: https://github.com/bgianfo ✅
2 changed files with 8 additions and 23 deletions
|
@ -10,20 +10,19 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/Locking/MutexProtected.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
static Singleton<MutexProtected<Custody::AllCustodiesList>> s_all_custodies;
|
||||
static Singleton<MutexProtected<Custody::AllCustodiesList>> s_all_instances;
|
||||
|
||||
static MutexProtected<Custody::AllCustodiesList>& all_custodies()
|
||||
MutexProtected<Custody::AllCustodiesList>& Custody::all_instances()
|
||||
{
|
||||
return s_all_custodies;
|
||||
return s_all_instances;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringView name, Inode& inode, int mount_flags)
|
||||
{
|
||||
return all_custodies().with_exclusive([&](auto& all_custodies) -> ErrorOr<NonnullRefPtr<Custody>> {
|
||||
return all_instances().with_exclusive([&](auto& all_custodies) -> ErrorOr<NonnullRefPtr<Custody>> {
|
||||
for (Custody& custody : all_custodies) {
|
||||
if (custody.parent() == parent
|
||||
&& custody.name() == name
|
||||
|
@ -40,20 +39,6 @@ ErrorOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringView
|
|||
});
|
||||
}
|
||||
|
||||
bool Custody::unref() const
|
||||
{
|
||||
bool should_destroy = all_custodies().with_exclusive([&](auto&) {
|
||||
if (deref_base())
|
||||
return false;
|
||||
m_all_custodies_list_node.remove();
|
||||
return true;
|
||||
});
|
||||
|
||||
if (should_destroy)
|
||||
delete this;
|
||||
return should_destroy;
|
||||
}
|
||||
|
||||
Custody::Custody(Custody* parent, NonnullOwnPtr<KString> name, Inode& inode, int mount_flags)
|
||||
: m_parent(parent)
|
||||
, m_name(move(name))
|
||||
|
|
|
@ -8,20 +8,19 @@
|
|||
|
||||
#include <AK/Error.h>
|
||||
#include <AK/IntrusiveList.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/String.h>
|
||||
#include <Kernel/Forward.h>
|
||||
#include <Kernel/KString.h>
|
||||
#include <Kernel/Library/ListedRefCounted.h>
|
||||
#include <Kernel/Locking/MutexProtected.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
// FIXME: Custody needs some locking.
|
||||
|
||||
class Custody : public RefCountedBase {
|
||||
class Custody : public ListedRefCounted<Custody, LockType::Mutex> {
|
||||
public:
|
||||
bool unref() const;
|
||||
|
||||
static ErrorOr<NonnullRefPtr<Custody>> try_create(Custody* parent, StringView name, Inode&, int mount_flags);
|
||||
|
||||
~Custody();
|
||||
|
@ -49,6 +48,7 @@ private:
|
|||
|
||||
public:
|
||||
using AllCustodiesList = IntrusiveList<&Custody::m_all_custodies_list_node>;
|
||||
static MutexProtected<Custody::AllCustodiesList>& all_instances();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue