mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:57:44 +00:00
Kernel: Make self-contained locking smart pointers their own classes
Until now, our kernel has reimplemented a number of AK classes to provide automatic internal locking: - RefPtr - NonnullRefPtr - WeakPtr - Weakable This patch renames the Kernel classes so that they can coexist with the original AK classes: - RefPtr => LockRefPtr - NonnullRefPtr => NonnullLockRefPtr - WeakPtr => LockWeakPtr - Weakable => LockWeakable The goal here is to eventually get rid of the Lock* classes in favor of using external locking.
This commit is contained in:
parent
e475263113
commit
11eee67b85
360 changed files with 1703 additions and 1672 deletions
|
@ -10,9 +10,9 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<SysFSBusDirectory> SysFSBusDirectory::must_create(SysFSRootDirectory const& parent_directory)
|
||||
UNMAP_AFTER_INIT NonnullLockRefPtr<SysFSBusDirectory> SysFSBusDirectory::must_create(SysFSRootDirectory const& parent_directory)
|
||||
{
|
||||
auto directory = adopt_ref(*new (nothrow) SysFSBusDirectory(parent_directory));
|
||||
auto directory = adopt_lock_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 NonnullRefPtr<SysFSBusDirectory> must_create(SysFSRootDirectory const&);
|
||||
static NonnullLockRefPtr<SysFSBusDirectory> must_create(SysFSRootDirectory const&);
|
||||
|
||||
private:
|
||||
explicit SysFSBusDirectory(SysFSRootDirectory const&);
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Kernel {
|
|||
|
||||
UNMAP_AFTER_INIT void PCIBusSysFSDirectory::initialize()
|
||||
{
|
||||
auto pci_directory = adopt_ref(*new (nothrow) PCIBusSysFSDirectory());
|
||||
auto pci_directory = adopt_lock_ref(*new (nothrow) PCIBusSysFSDirectory());
|
||||
SysFSComponentRegistry::the().register_new_bus_directory(pci_directory);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,9 +48,9 @@ StringView PCIDeviceAttributeSysFSComponent::name() const
|
|||
}
|
||||
}
|
||||
|
||||
NonnullRefPtr<PCIDeviceAttributeSysFSComponent> PCIDeviceAttributeSysFSComponent::create(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width)
|
||||
NonnullLockRefPtr<PCIDeviceAttributeSysFSComponent> PCIDeviceAttributeSysFSComponent::create(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) PCIDeviceAttributeSysFSComponent(device, offset, field_bytes_width));
|
||||
return adopt_lock_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 NonnullRefPtr<PCIDeviceAttributeSysFSComponent> create(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width);
|
||||
static NonnullLockRefPtr<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);
|
||||
NonnullRefPtr<PCIDeviceSysFSDirectory> m_device;
|
||||
NonnullLockRefPtr<PCIDeviceSysFSDirectory> m_device;
|
||||
PCI::RegisterOffset m_offset;
|
||||
size_t m_field_bytes_width;
|
||||
};
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<PCIDeviceSysFSDirectory> PCIDeviceSysFSDirectory::create(SysFSDirectory const& parent_directory, PCI::Address address)
|
||||
UNMAP_AFTER_INIT NonnullLockRefPtr<PCIDeviceSysFSDirectory> PCIDeviceSysFSDirectory::create(SysFSDirectory const& parent_directory, PCI::Address address)
|
||||
{
|
||||
// FIXME: Handle allocation failure gracefully
|
||||
auto device_name = MUST(KString::formatted("{:04x}:{:02x}:{:02x}.{}", address.domain(), address.bus(), address.device(), address.function()));
|
||||
auto directory = adopt_ref(*new (nothrow) PCIDeviceSysFSDirectory(move(device_name), parent_directory, address));
|
||||
auto directory = adopt_lock_ref(*new (nothrow) PCIDeviceSysFSDirectory(move(device_name), parent_directory, address));
|
||||
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));
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Kernel {
|
|||
|
||||
class PCIDeviceSysFSDirectory final : public SysFSDirectory {
|
||||
public:
|
||||
static NonnullRefPtr<PCIDeviceSysFSDirectory> create(SysFSDirectory const&, PCI::Address);
|
||||
static NonnullLockRefPtr<PCIDeviceSysFSDirectory> create(SysFSDirectory const&, PCI::Address);
|
||||
PCI::Address const& address() const { return m_address; }
|
||||
|
||||
virtual StringView name() const override { return m_device_directory_name->view(); }
|
||||
|
|
|
@ -40,7 +40,7 @@ UNMAP_AFTER_INIT SysFSUSBBusDirectory::SysFSUSBBusDirectory(SysFSBusDirectory& b
|
|||
|
||||
UNMAP_AFTER_INIT void SysFSUSBBusDirectory::initialize()
|
||||
{
|
||||
auto directory = adopt_ref(*new SysFSUSBBusDirectory(SysFSComponentRegistry::the().buses_directory()));
|
||||
auto directory = adopt_lock_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<NonnullRefPtr<SysFSUSBDeviceInformation>> SysFSUSBDeviceInformation::create(USB::Device& device)
|
||||
ErrorOr<NonnullLockRefPtr<SysFSUSBDeviceInformation>> SysFSUSBDeviceInformation::create(USB::Device& device)
|
||||
{
|
||||
auto device_name = TRY(KString::number(device.address()));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) SysFSUSBDeviceInformation(move(device_name), device));
|
||||
return adopt_nonnull_lock_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<NonnullRefPtr<SysFSUSBDeviceInformation>> create(USB::Device&);
|
||||
static ErrorOr<NonnullLockRefPtr<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;
|
||||
|
||||
NonnullRefPtr<USB::Device> m_device;
|
||||
NonnullLockRefPtr<USB::Device> m_device;
|
||||
|
||||
private:
|
||||
ErrorOr<void> try_generate(KBufferBuilder&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue