mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
Ext2FS: Free Ext2FSInodes when the last user releases them.
The inode cache was keeping these alive forever. Added a cute little magic trick to Retainable that calls T::one_retain_left() when the retain count is decremented to 1.
This commit is contained in:
parent
42d9f18cae
commit
741349502f
Notes:
sideshowbarker
2024-07-19 16:06:20 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/741349502fa
4 changed files with 26 additions and 1 deletions
|
@ -17,6 +17,18 @@ constexpr auto call_will_be_destroyed_if_present(...) -> FalseType
|
|||
return { };
|
||||
}
|
||||
|
||||
template<class T>
|
||||
constexpr auto call_one_retain_left_if_present(T* object) -> decltype(object->one_retain_left(), TrueType { })
|
||||
{
|
||||
object->one_retain_left();
|
||||
return { };
|
||||
}
|
||||
|
||||
constexpr auto call_one_retain_left_if_present(...) -> FalseType
|
||||
{
|
||||
return { };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class Retainable {
|
||||
public:
|
||||
|
@ -29,9 +41,12 @@ public:
|
|||
void release()
|
||||
{
|
||||
ASSERT(m_retain_count);
|
||||
if (!--m_retain_count) {
|
||||
--m_retain_count;
|
||||
if (m_retain_count == 0) {
|
||||
call_will_be_destroyed_if_present(static_cast<T*>(this));
|
||||
delete static_cast<T*>(this);
|
||||
} else if (m_retain_count == 1) {
|
||||
call_one_retain_left_if_present(static_cast<T*>(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -985,3 +985,8 @@ String Ext2FSInode::reverse_lookup(InodeIdentifier child_id)
|
|||
}
|
||||
return { };
|
||||
}
|
||||
|
||||
void Ext2FSInode::one_retain_left()
|
||||
{
|
||||
fs().m_inode_cache.remove(index());
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ public:
|
|||
size_t size() const { return m_raw_inode.i_size; }
|
||||
bool is_symlink() const { return isSymbolicLink(m_raw_inode.i_mode); }
|
||||
|
||||
// ^Inode (Retainable magic)
|
||||
virtual void one_retain_left() override;
|
||||
|
||||
private:
|
||||
// ^Inode
|
||||
virtual ssize_t read_bytes(Unix::off_t, size_t, byte* buffer, FileDescriptor*) override;
|
||||
|
|
|
@ -63,6 +63,8 @@ class Inode : public Retainable<Inode> {
|
|||
public:
|
||||
virtual ~Inode();
|
||||
|
||||
virtual void one_retain_left() { }
|
||||
|
||||
FS& fs() { return m_fs; }
|
||||
const FS& fs() const { return m_fs; }
|
||||
unsigned fsid() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue