1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

Kernel: Switch LockRefPtr<Inode> to RefPtr<Inode>

The main place where this is a little iffy is in RAMFS where inodes
have a LockWeakPtr to their parent inode. I've left that as a
LockWeakPtr for now.
This commit is contained in:
Andreas Kling 2023-03-07 12:25:00 +01:00
parent 067d0689c5
commit e6fc7b3ff7
50 changed files with 143 additions and 144 deletions

View file

@ -143,7 +143,7 @@ public:
// use unsafe_ptr(), but as the name suggests, it is not safe...
LockRefPtr<T> ref;
// Using do_while_locked protects against a race with clear()!
m_link.do_while_locked([&](WeakLink* link) {
m_link.do_while_locked([&](LockWeakLink* link) {
if (link)
ref = link->template strong_ref<T>();
});
@ -153,7 +153,7 @@ public:
[[nodiscard]] T* unsafe_ptr() const
{
T* ptr = nullptr;
m_link.do_while_locked([&](WeakLink* link) {
m_link.do_while_locked([&](LockWeakLink* link) {
if (link)
ptr = link->unsafe_ptr<T>();
});
@ -165,15 +165,15 @@ public:
[[nodiscard]] bool is_null() const { return !m_link || m_link->is_null(); }
void clear() { m_link = nullptr; }
[[nodiscard]] LockRefPtr<WeakLink> take_link() { return move(m_link); }
[[nodiscard]] LockRefPtr<LockWeakLink> take_link() { return move(m_link); }
private:
LockWeakPtr(LockRefPtr<WeakLink> const& link)
LockWeakPtr(LockRefPtr<LockWeakLink> const& link)
: m_link(link)
{
}
LockRefPtr<WeakLink> m_link;
LockRefPtr<LockWeakLink> m_link;
};
template<typename T>
@ -196,10 +196,10 @@ inline ErrorOr<LockWeakPtr<U>> LockWeakable<T>::try_make_weak_ptr() const
return LockWeakPtr<U> {};
}
if (!m_link) {
// There is a small chance that we create a new WeakLink and throw
// There is a small chance that we create a new LockWeakLink and throw
// it away because another thread beat us to it. But the window is
// pretty small and the overhead isn't terrible.
m_link.assign_if_null(TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) WeakLink(const_cast<T&>(static_cast<T const&>(*this))))));
m_link.assign_if_null(TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) LockWeakLink(const_cast<T&>(static_cast<T const&>(*this))))));
}
LockWeakPtr<U> weak_ptr(m_link);