mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:27:43 +00:00
Kernel: Get rid of *LockRefPtr in the SysFS filesystem code
To do this we also need to get rid of LockRefPtrs in the USB code as well. Most of the SysFS nodes are statically generated during boot and are not mutated afterwards. The same goes for general device code - once we generate the appropriate SysFS nodes, we almost never mutate the node pointers afterwards, making locking unnecessary.
This commit is contained in:
parent
dd7633c5f4
commit
b02ee664e7
114 changed files with 230 additions and 218 deletions
|
@ -10,9 +10,9 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
UNMAP_AFTER_INIT NonnullLockRefPtr<SysFSBusDirectory> SysFSBusDirectory::must_create(SysFSRootDirectory const& parent_directory)
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<SysFSBusDirectory> SysFSBusDirectory::must_create(SysFSRootDirectory const& parent_directory)
|
||||
{
|
||||
auto directory = adopt_lock_ref(*new (nothrow) SysFSBusDirectory(parent_directory));
|
||||
auto directory = adopt_ref(*new (nothrow) SysFSBusDirectory(parent_directory));
|
||||
return directory;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class SysFSBusDirectory : public SysFSDirectory {
|
|||
|
||||
public:
|
||||
virtual StringView name() const override { return "bus"sv; }
|
||||
static NonnullLockRefPtr<SysFSBusDirectory> must_create(SysFSRootDirectory const&);
|
||||
static NonnullRefPtr<SysFSBusDirectory> must_create(SysFSRootDirectory const&);
|
||||
|
||||
private:
|
||||
explicit SysFSBusDirectory(SysFSRootDirectory const&);
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Kernel {
|
|||
|
||||
UNMAP_AFTER_INIT void PCIBusSysFSDirectory::initialize()
|
||||
{
|
||||
auto pci_directory = adopt_lock_ref(*new (nothrow) PCIBusSysFSDirectory());
|
||||
auto pci_directory = adopt_ref(*new (nothrow) PCIBusSysFSDirectory());
|
||||
SysFSComponentRegistry::the().register_new_bus_directory(pci_directory);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,9 +47,9 @@ StringView PCIDeviceAttributeSysFSComponent::name() const
|
|||
}
|
||||
}
|
||||
|
||||
NonnullLockRefPtr<PCIDeviceAttributeSysFSComponent> PCIDeviceAttributeSysFSComponent::create(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width)
|
||||
NonnullRefPtr<PCIDeviceAttributeSysFSComponent> PCIDeviceAttributeSysFSComponent::create(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width)
|
||||
{
|
||||
return adopt_lock_ref(*new (nothrow) PCIDeviceAttributeSysFSComponent(device, offset, field_bytes_width));
|
||||
return adopt_ref(*new (nothrow) PCIDeviceAttributeSysFSComponent(device, offset, field_bytes_width));
|
||||
}
|
||||
|
||||
PCIDeviceAttributeSysFSComponent::PCIDeviceAttributeSysFSComponent(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width)
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Kernel {
|
|||
|
||||
class PCIDeviceAttributeSysFSComponent : public SysFSComponent {
|
||||
public:
|
||||
static NonnullLockRefPtr<PCIDeviceAttributeSysFSComponent> create(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width);
|
||||
static NonnullRefPtr<PCIDeviceAttributeSysFSComponent> create(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width);
|
||||
|
||||
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override;
|
||||
virtual ~PCIDeviceAttributeSysFSComponent() {};
|
||||
|
@ -25,7 +25,7 @@ public:
|
|||
protected:
|
||||
ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const;
|
||||
PCIDeviceAttributeSysFSComponent(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width);
|
||||
NonnullLockRefPtr<PCIDeviceSysFSDirectory> m_device;
|
||||
NonnullRefPtr<PCIDeviceSysFSDirectory> m_device;
|
||||
PCI::RegisterOffset m_offset;
|
||||
size_t m_field_bytes_width;
|
||||
};
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
UNMAP_AFTER_INIT NonnullLockRefPtr<PCIDeviceSysFSDirectory> PCIDeviceSysFSDirectory::create(SysFSDirectory const& parent_directory, PCI::DeviceIdentifier const& device_identifier)
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<PCIDeviceSysFSDirectory> PCIDeviceSysFSDirectory::create(SysFSDirectory const& parent_directory, PCI::DeviceIdentifier const& device_identifier)
|
||||
{
|
||||
// FIXME: Handle allocation failure gracefully
|
||||
auto& address = device_identifier.address();
|
||||
auto device_name = MUST(KString::formatted("{:04x}:{:02x}:{:02x}.{}", address.domain(), address.bus(), address.device(), address.function()));
|
||||
auto directory = adopt_lock_ref(*new (nothrow) PCIDeviceSysFSDirectory(move(device_name), parent_directory, device_identifier));
|
||||
auto directory = adopt_ref(*new (nothrow) PCIDeviceSysFSDirectory(move(device_name), parent_directory, device_identifier));
|
||||
MUST(directory->m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||
list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::VENDOR_ID, 2));
|
||||
list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::DEVICE_ID, 2));
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Kernel {
|
|||
|
||||
class PCIDeviceSysFSDirectory final : public SysFSDirectory {
|
||||
public:
|
||||
static NonnullLockRefPtr<PCIDeviceSysFSDirectory> create(SysFSDirectory const&, PCI::DeviceIdentifier const&);
|
||||
static NonnullRefPtr<PCIDeviceSysFSDirectory> create(SysFSDirectory const&, PCI::DeviceIdentifier const&);
|
||||
PCI::DeviceIdentifier const& device_identifier() const { return *m_device_identifier; }
|
||||
|
||||
virtual StringView name() const override { return m_device_directory_name->view(); }
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullLockRefPtr<PCIDeviceExpansionROMSysFSComponent> PCIDeviceExpansionROMSysFSComponent::create(PCIDeviceSysFSDirectory const& device)
|
||||
NonnullRefPtr<PCIDeviceExpansionROMSysFSComponent> PCIDeviceExpansionROMSysFSComponent::create(PCIDeviceSysFSDirectory const& device)
|
||||
{
|
||||
auto option_rom_size = PCI::get_expansion_rom_space_size(device.device_identifier());
|
||||
return adopt_lock_ref(*new (nothrow) PCIDeviceExpansionROMSysFSComponent(device, option_rom_size));
|
||||
return adopt_ref(*new (nothrow) PCIDeviceExpansionROMSysFSComponent(device, option_rom_size));
|
||||
}
|
||||
|
||||
PCIDeviceExpansionROMSysFSComponent::PCIDeviceExpansionROMSysFSComponent(PCIDeviceSysFSDirectory const& device, size_t option_rom_size)
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Kernel {
|
|||
|
||||
class PCIDeviceExpansionROMSysFSComponent : public SysFSComponent {
|
||||
public:
|
||||
static NonnullLockRefPtr<PCIDeviceExpansionROMSysFSComponent> create(PCIDeviceSysFSDirectory const& device);
|
||||
static NonnullRefPtr<PCIDeviceExpansionROMSysFSComponent> create(PCIDeviceSysFSDirectory const& device);
|
||||
|
||||
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override;
|
||||
virtual ~PCIDeviceExpansionROMSysFSComponent() {};
|
||||
|
@ -25,7 +25,7 @@ public:
|
|||
protected:
|
||||
ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer(size_t offset_in_rom, size_t count) const;
|
||||
PCIDeviceExpansionROMSysFSComponent(PCIDeviceSysFSDirectory const& device, size_t option_rom_size);
|
||||
NonnullLockRefPtr<PCIDeviceSysFSDirectory> m_device;
|
||||
NonnullRefPtr<PCIDeviceSysFSDirectory> m_device;
|
||||
size_t const m_option_rom_size { 0 };
|
||||
};
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ UNMAP_AFTER_INIT SysFSUSBBusDirectory::SysFSUSBBusDirectory(SysFSBusDirectory& b
|
|||
|
||||
UNMAP_AFTER_INIT void SysFSUSBBusDirectory::initialize()
|
||||
{
|
||||
auto directory = adopt_lock_ref(*new SysFSUSBBusDirectory(SysFSComponentRegistry::the().buses_directory()));
|
||||
auto directory = adopt_ref(*new SysFSUSBBusDirectory(SysFSComponentRegistry::the().buses_directory()));
|
||||
SysFSComponentRegistry::the().register_new_bus_directory(directory);
|
||||
s_sysfs_usb_bus_directory = directory;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<SysFSUSBDeviceInformation>> SysFSUSBDeviceInformation::create(USB::Device& device)
|
||||
ErrorOr<NonnullRefPtr<SysFSUSBDeviceInformation>> SysFSUSBDeviceInformation::create(USB::Device& device)
|
||||
{
|
||||
auto device_name = TRY(KString::number(device.address()));
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) SysFSUSBDeviceInformation(move(device_name), device));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) SysFSUSBDeviceInformation(move(device_name), device));
|
||||
}
|
||||
|
||||
SysFSUSBDeviceInformation::SysFSUSBDeviceInformation(NonnullOwnPtr<KString> device_name, USB::Device& device)
|
||||
|
|
|
@ -20,7 +20,7 @@ class SysFSUSBDeviceInformation : public SysFSComponent {
|
|||
public:
|
||||
virtual ~SysFSUSBDeviceInformation() override;
|
||||
|
||||
static ErrorOr<NonnullLockRefPtr<SysFSUSBDeviceInformation>> create(USB::Device&);
|
||||
static ErrorOr<NonnullRefPtr<SysFSUSBDeviceInformation>> create(USB::Device&);
|
||||
virtual StringView name() const override { return m_device_name->view(); }
|
||||
|
||||
protected:
|
||||
|
@ -28,7 +28,7 @@ protected:
|
|||
|
||||
virtual ErrorOr<size_t> read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
|
||||
|
||||
NonnullLockRefPtr<USB::Device> m_device;
|
||||
NonnullRefPtr<USB::Device> m_device;
|
||||
|
||||
private:
|
||||
ErrorOr<void> try_generate(KBufferBuilder&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue