From 4a3a947df3f9722065b5c938a75d9d651ae1ff03 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Wed, 29 Dec 2021 01:00:29 +0200 Subject: [PATCH] Kernel: Rename File::{before_removing => will_be_destroyed} This will allow File and it's descendants to use RefCounted instead of having a custom implementation of unref. (Since RefCounted calls will_be_destroyed automatically) This commit also removes an erroneous call to `before_removing` in AHCIPort, this is a duplicate call, as the only reference to the device is immediately dropped following the call, which in turns calls `before_removing` via File::unref. --- Kernel/Devices/Device.cpp | 2 +- Kernel/Devices/Device.h | 2 +- Kernel/FileSystem/File.cpp | 2 +- Kernel/FileSystem/File.h | 2 +- Kernel/Storage/ATA/AHCIPort.cpp | 1 - Kernel/TTY/SlavePTY.cpp | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Kernel/Devices/Device.cpp b/Kernel/Devices/Device.cpp index 5f239dc3ff..65454e1d9b 100644 --- a/Kernel/Devices/Device.cpp +++ b/Kernel/Devices/Device.cpp @@ -131,7 +131,7 @@ void Device::after_inserting() }); } -void Device::before_removing() +void Device::will_be_destroyed() { VERIFY(m_sysfs_component); SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void { diff --git a/Kernel/Devices/Device.h b/Kernel/Devices/Device.h index 100a8d7a83..383584885c 100644 --- a/Kernel/Devices/Device.h +++ b/Kernel/Devices/Device.h @@ -47,7 +47,7 @@ public: GroupID gid() const { return m_gid; } virtual bool is_device() const override { return true; } - virtual void before_removing() override; + virtual void will_be_destroyed() override; virtual void after_inserting(); void process_next_queued_request(Badge, const AsyncDeviceRequest&); diff --git a/Kernel/FileSystem/File.cpp b/Kernel/FileSystem/File.cpp index 527d48d922..612ad2ffce 100644 --- a/Kernel/FileSystem/File.cpp +++ b/Kernel/FileSystem/File.cpp @@ -24,7 +24,7 @@ bool File::unref() const { if (deref_base()) return false; - const_cast(*this).before_removing(); + const_cast(*this).will_be_destroyed(); delete this; return true; } diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index 891eae69fe..6c2c9388cb 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -75,7 +75,7 @@ class File , public Weakable { public: virtual bool unref() const; - virtual void before_removing() { } + virtual void will_be_destroyed() { } virtual ~File(); virtual ErrorOr> open(int options); diff --git a/Kernel/Storage/ATA/AHCIPort.cpp b/Kernel/Storage/ATA/AHCIPort.cpp index 3cac75f344..b84c39317f 100644 --- a/Kernel/Storage/ATA/AHCIPort.cpp +++ b/Kernel/Storage/ATA/AHCIPort.cpp @@ -77,7 +77,6 @@ void AHCIPort::handle_interrupt() m_connected_device->prepare_for_unplug(); StorageManagement::the().remove_device(*m_connected_device); g_io_work->queue([this]() { - m_connected_device->before_removing(); m_connected_device.clear(); }); } else { diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp index 200072d4b0..512f54e383 100644 --- a/Kernel/TTY/SlavePTY.cpp +++ b/Kernel/TTY/SlavePTY.cpp @@ -29,7 +29,7 @@ bool SlavePTY::unref() const return true; }); if (did_hit_zero) { - const_cast(*this).before_removing(); + const_cast(*this).will_be_destroyed(); delete this; } return did_hit_zero;