diff options
author | Andreas Kling <kling@serenityos.org> | 2022-08-19 20:53:40 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-20 17:20:43 +0200 |
commit | 11eee67b8510767d76fb4793e3b62ac1793dd723 (patch) | |
tree | 8ce47a3813ce74bba56c60f62b29bdd6cdf287da /Kernel/Bus/USB | |
parent | e475263113387404e63cdc3666391934604eb6e7 (diff) | |
download | serenity-11eee67b8510767d76fb4793e3b62ac1793dd723.zip |
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.
Diffstat (limited to 'Kernel/Bus/USB')
-rw-r--r-- | Kernel/Bus/USB/UHCI/UHCIController.cpp | 6 | ||||
-rw-r--r-- | Kernel/Bus/USB/UHCI/UHCIController.h | 2 | ||||
-rw-r--r-- | Kernel/Bus/USB/UHCI/UHCIRootHub.cpp | 4 | ||||
-rw-r--r-- | Kernel/Bus/USB/UHCI/UHCIRootHub.h | 10 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBController.h | 2 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBDevice.cpp | 6 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBDevice.h | 10 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBHub.cpp | 12 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBHub.h | 6 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBManagement.h | 4 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBPipe.h | 2 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBTransfer.cpp | 4 | ||||
-rw-r--r-- | Kernel/Bus/USB/USBTransfer.h | 4 |
13 files changed, 36 insertions, 36 deletions
diff --git a/Kernel/Bus/USB/UHCI/UHCIController.cpp b/Kernel/Bus/USB/UHCI/UHCIController.cpp index 7fa405f000..b8b9062f80 100644 --- a/Kernel/Bus/USB/UHCI/UHCIController.cpp +++ b/Kernel/Bus/USB/UHCI/UHCIController.cpp @@ -62,10 +62,10 @@ static constexpr u16 UHCI_PORTSC_NON_WRITE_CLEAR_BIT_MASK = 0x1FF5; // This is u static constexpr u8 UHCI_NUMBER_OF_ISOCHRONOUS_TDS = 128; static constexpr u16 UHCI_NUMBER_OF_FRAMES = 1024; -ErrorOr<NonnullRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) +ErrorOr<NonnullLockRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) { // NOTE: This assumes that address is pointing to a valid UHCI controller. - auto controller = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) UHCIController(pci_device_identifier))); + auto controller = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) UHCIController(pci_device_identifier))); TRY(controller->initialize()); return controller; } @@ -510,7 +510,7 @@ size_t UHCIController::poll_transfer_queue(QueueHead& transfer_queue) ErrorOr<void> UHCIController::spawn_port_process() { - RefPtr<Thread> usb_hotplug_thread; + LockRefPtr<Thread> usb_hotplug_thread; (void)Process::create_kernel_process(usb_hotplug_thread, TRY(KString::try_create("UHCI Hot Plug Task"sv)), [&] { for (;;) { if (m_root_hub) diff --git a/Kernel/Bus/USB/UHCI/UHCIController.h b/Kernel/Bus/USB/UHCI/UHCIController.h index a0d2dec5c6..7735bf4e53 100644 --- a/Kernel/Bus/USB/UHCI/UHCIController.h +++ b/Kernel/Bus/USB/UHCI/UHCIController.h @@ -33,7 +33,7 @@ class UHCIController final public: static constexpr u8 NUMBER_OF_ROOT_PORTS = 2; - static ErrorOr<NonnullRefPtr<UHCIController>> try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier); + static ErrorOr<NonnullLockRefPtr<UHCIController>> try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier); virtual ~UHCIController() override; virtual StringView purpose() const override { return "UHCI"sv; } diff --git a/Kernel/Bus/USB/UHCI/UHCIRootHub.cpp b/Kernel/Bus/USB/UHCI/UHCIRootHub.cpp index 2f3632c178..222ca93e2b 100644 --- a/Kernel/Bus/USB/UHCI/UHCIRootHub.cpp +++ b/Kernel/Bus/USB/UHCI/UHCIRootHub.cpp @@ -83,12 +83,12 @@ static USBHubDescriptor uhci_root_hub_hub_descriptor = { 0x0, // Self-powered }; -ErrorOr<NonnullOwnPtr<UHCIRootHub>> UHCIRootHub::try_create(NonnullRefPtr<UHCIController> uhci_controller) +ErrorOr<NonnullOwnPtr<UHCIRootHub>> UHCIRootHub::try_create(NonnullLockRefPtr<UHCIController> uhci_controller) { return adopt_nonnull_own_or_enomem(new (nothrow) UHCIRootHub(move(uhci_controller))); } -UHCIRootHub::UHCIRootHub(NonnullRefPtr<UHCIController> uhci_controller) +UHCIRootHub::UHCIRootHub(NonnullLockRefPtr<UHCIController> uhci_controller) : m_uhci_controller(move(uhci_controller)) { } diff --git a/Kernel/Bus/USB/UHCI/UHCIRootHub.h b/Kernel/Bus/USB/UHCI/UHCIRootHub.h index bcfd8ba850..3bce1d54e9 100644 --- a/Kernel/Bus/USB/UHCI/UHCIRootHub.h +++ b/Kernel/Bus/USB/UHCI/UHCIRootHub.h @@ -8,9 +8,9 @@ #include <AK/Error.h> #include <AK/NonnullOwnPtr.h> -#include <AK/NonnullRefPtr.h> #include <Kernel/Bus/USB/USBHub.h> #include <Kernel/Bus/USB/USBTransfer.h> +#include <Kernel/Library/NonnullLockRefPtr.h> namespace Kernel::USB { @@ -18,9 +18,9 @@ class UHCIController; class UHCIRootHub { public: - static ErrorOr<NonnullOwnPtr<UHCIRootHub>> try_create(NonnullRefPtr<UHCIController>); + static ErrorOr<NonnullOwnPtr<UHCIRootHub>> try_create(NonnullLockRefPtr<UHCIController>); - UHCIRootHub(NonnullRefPtr<UHCIController>); + UHCIRootHub(NonnullLockRefPtr<UHCIController>); ~UHCIRootHub() = default; ErrorOr<void> setup(Badge<UHCIController>); @@ -32,8 +32,8 @@ public: void check_for_port_updates() { m_hub->check_for_port_updates(); } private: - NonnullRefPtr<UHCIController> m_uhci_controller; - RefPtr<Hub> m_hub; + NonnullLockRefPtr<UHCIController> m_uhci_controller; + LockRefPtr<Hub> m_hub; }; } diff --git a/Kernel/Bus/USB/USBController.h b/Kernel/Bus/USB/USBController.h index 0f8c38dddb..47fc1d1d6d 100644 --- a/Kernel/Bus/USB/USBController.h +++ b/Kernel/Bus/USB/USBController.h @@ -31,7 +31,7 @@ public: private: u8 m_next_device_index { 1 }; - IntrusiveListNode<USBController, NonnullRefPtr<USBController>> m_controller_list_node; + IntrusiveListNode<USBController, NonnullLockRefPtr<USBController>> m_controller_list_node; public: using List = IntrusiveList<&USBController::m_controller_list_node>; diff --git a/Kernel/Bus/USB/USBDevice.cpp b/Kernel/Bus/USB/USBDevice.cpp index 1aa049dd50..955da88ae7 100644 --- a/Kernel/Bus/USB/USBDevice.cpp +++ b/Kernel/Bus/USB/USBDevice.cpp @@ -16,10 +16,10 @@ namespace Kernel::USB { -ErrorOr<NonnullRefPtr<Device>> Device::try_create(USBController const& controller, u8 port, DeviceSpeed speed) +ErrorOr<NonnullLockRefPtr<Device>> Device::try_create(USBController const& controller, u8 port, DeviceSpeed speed) { auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0)); - auto device = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Device(controller, port, speed, move(pipe)))); + auto device = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) Device(controller, port, speed, move(pipe)))); auto sysfs_node = TRY(SysFSUSBDeviceInformation::create(*device)); device->m_sysfs_device_info_node = move(sysfs_node); TRY(device->enumerate_device()); @@ -35,7 +35,7 @@ Device::Device(USBController const& controller, u8 port, DeviceSpeed speed, Nonn { } -Device::Device(NonnullRefPtr<USBController> controller, u8 address, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe) +Device::Device(NonnullLockRefPtr<USBController> controller, u8 address, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe) : m_device_port(port) , m_device_speed(speed) , m_address(address) diff --git a/Kernel/Bus/USB/USBDevice.h b/Kernel/Bus/USB/USBDevice.h index f74c3316b4..0eb5b20718 100644 --- a/Kernel/Bus/USB/USBDevice.h +++ b/Kernel/Bus/USB/USBDevice.h @@ -34,7 +34,7 @@ public: LowSpeed }; - static ErrorOr<NonnullRefPtr<Device>> try_create(USBController const&, u8, DeviceSpeed); + static ErrorOr<NonnullLockRefPtr<Device>> try_create(USBController const&, u8, DeviceSpeed); Device(USBController const&, u8, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe); Device(Device const& device, NonnullOwnPtr<Pipe> default_pipe); @@ -59,7 +59,7 @@ public: SysFSUSBDeviceInformation& sysfs_device_info_node(Badge<USB::Hub>) { return *m_sysfs_device_info_node; } protected: - Device(NonnullRefPtr<USBController> controller, u8 address, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe); + Device(NonnullLockRefPtr<USBController> controller, u8 address, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe); u8 m_device_port { 0 }; // What port is this device attached to. NOTE: This is 1-based. DeviceSpeed m_device_speed; // What speed is this device running at @@ -71,14 +71,14 @@ protected: USBDeviceDescriptor m_device_descriptor {}; // Device Descriptor obtained from USB Device Vector<USBConfiguration> m_configurations; // Configurations for this device - NonnullRefPtr<USBController> m_controller; + NonnullLockRefPtr<USBController> m_controller; NonnullOwnPtr<Pipe> m_default_pipe; // Default communication pipe (endpoint0) used during enumeration private: - IntrusiveListNode<Device, NonnullRefPtr<Device>> m_hub_child_node; + IntrusiveListNode<Device, NonnullLockRefPtr<Device>> m_hub_child_node; protected: - RefPtr<SysFSUSBDeviceInformation> m_sysfs_device_info_node; + LockRefPtr<SysFSUSBDeviceInformation> m_sysfs_device_info_node; public: using List = IntrusiveList<&Device::m_hub_child_node>; diff --git a/Kernel/Bus/USB/USBHub.cpp b/Kernel/Bus/USB/USBHub.cpp index 8c0bf5e701..1a7e19e4e2 100644 --- a/Kernel/Bus/USB/USBHub.cpp +++ b/Kernel/Bus/USB/USBHub.cpp @@ -14,23 +14,23 @@ namespace Kernel::USB { -ErrorOr<NonnullRefPtr<Hub>> Hub::try_create_root_hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed) +ErrorOr<NonnullLockRefPtr<Hub>> Hub::try_create_root_hub(NonnullLockRefPtr<USBController> controller, DeviceSpeed device_speed) { // NOTE: Enumeration does not happen here, as the controller must know what the device address is at all times during enumeration to intercept requests. auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0)); - auto hub = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Hub(controller, device_speed, move(pipe)))); + auto hub = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) Hub(controller, device_speed, move(pipe)))); return hub; } -ErrorOr<NonnullRefPtr<Hub>> Hub::try_create_from_device(Device const& device) +ErrorOr<NonnullLockRefPtr<Hub>> Hub::try_create_from_device(Device const& device) { auto pipe = TRY(Pipe::try_create_pipe(device.controller(), Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, device.device_descriptor().max_packet_size, device.address())); - auto hub = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Hub(device, move(pipe)))); + auto hub = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) Hub(device, move(pipe)))); TRY(hub->enumerate_and_power_on_hub()); return hub; } -Hub::Hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed, NonnullOwnPtr<Pipe> default_pipe) +Hub::Hub(NonnullLockRefPtr<USBController> controller, DeviceSpeed device_speed, NonnullOwnPtr<Pipe> default_pipe) : Device(move(controller), 1 /* Port 1 */, device_speed, move(default_pipe)) { } @@ -266,7 +266,7 @@ void Hub::check_for_port_updates() } else { dbgln("USB Hub: Device detached on port {}!", port_number); - RefPtr<Device> device_to_remove = nullptr; + LockRefPtr<Device> device_to_remove = nullptr; for (auto& child : m_children) { if (port_number == child.port()) { device_to_remove = &child; diff --git a/Kernel/Bus/USB/USBHub.h b/Kernel/Bus/USB/USBHub.h index d4b7de4e44..aaefe513d4 100644 --- a/Kernel/Bus/USB/USBHub.h +++ b/Kernel/Bus/USB/USBHub.h @@ -79,8 +79,8 @@ static constexpr u16 PORT_STATUS_RESET_CHANGED = (1 << 4); class Hub : public Device { public: - static ErrorOr<NonnullRefPtr<Hub>> try_create_root_hub(NonnullRefPtr<USBController>, DeviceSpeed); - static ErrorOr<NonnullRefPtr<Hub>> try_create_from_device(Device const&); + static ErrorOr<NonnullLockRefPtr<Hub>> try_create_root_hub(NonnullLockRefPtr<USBController>, DeviceSpeed); + static ErrorOr<NonnullLockRefPtr<Hub>> try_create_from_device(Device const&); virtual ~Hub() override = default; @@ -96,7 +96,7 @@ public: private: // Root Hub constructor - Hub(NonnullRefPtr<USBController>, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe); + Hub(NonnullLockRefPtr<USBController>, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe); Hub(Device const&, NonnullOwnPtr<Pipe> default_pipe); diff --git a/Kernel/Bus/USB/USBManagement.h b/Kernel/Bus/USB/USBManagement.h index b275facc8e..9d8da80afe 100644 --- a/Kernel/Bus/USB/USBManagement.h +++ b/Kernel/Bus/USB/USBManagement.h @@ -6,9 +6,9 @@ #pragma once -#include <AK/NonnullRefPtr.h> -#include <AK/NonnullRefPtrVector.h> #include <Kernel/Bus/USB/USBController.h> +#include <Kernel/Library/NonnullLockRefPtr.h> +#include <Kernel/Library/NonnullLockRefPtrVector.h> namespace Kernel::USB { diff --git a/Kernel/Bus/USB/USBPipe.h b/Kernel/Bus/USB/USBPipe.h index eb01d34177..a91de384ab 100644 --- a/Kernel/Bus/USB/USBPipe.h +++ b/Kernel/Bus/USB/USBPipe.h @@ -67,7 +67,7 @@ public: private: friend class Device; - NonnullRefPtr<USBController> m_controller; + NonnullLockRefPtr<USBController> m_controller; Type m_type; Direction m_direction; diff --git a/Kernel/Bus/USB/USBTransfer.cpp b/Kernel/Bus/USB/USBTransfer.cpp index 4f489389f2..e3a0e75d3b 100644 --- a/Kernel/Bus/USB/USBTransfer.cpp +++ b/Kernel/Bus/USB/USBTransfer.cpp @@ -9,9 +9,9 @@ namespace Kernel::USB { -ErrorOr<NonnullRefPtr<Transfer>> Transfer::try_create(Pipe& pipe, u16 length, Memory::Region& dma_buffer) +ErrorOr<NonnullLockRefPtr<Transfer>> Transfer::try_create(Pipe& pipe, u16 length, Memory::Region& dma_buffer) { - return adopt_nonnull_ref_or_enomem(new (nothrow) Transfer(pipe, length, dma_buffer)); + return adopt_nonnull_lock_ref_or_enomem(new (nothrow) Transfer(pipe, length, dma_buffer)); } Transfer::Transfer(Pipe& pipe, u16 len, Memory::Region& dma_buffer) diff --git a/Kernel/Bus/USB/USBTransfer.h b/Kernel/Bus/USB/USBTransfer.h index 92fa48e1af..5923542d6c 100644 --- a/Kernel/Bus/USB/USBTransfer.h +++ b/Kernel/Bus/USB/USBTransfer.h @@ -8,9 +8,9 @@ #include <AK/AtomicRefCounted.h> #include <AK/OwnPtr.h> -#include <AK/RefPtr.h> #include <Kernel/Bus/USB/PacketTypes.h> #include <Kernel/Bus/USB/USBPipe.h> +#include <Kernel/Library/LockRefPtr.h> #include <Kernel/Memory/AnonymousVMObject.h> #include <Kernel/Memory/PhysicalPage.h> #include <Kernel/Memory/Region.h> @@ -20,7 +20,7 @@ namespace Kernel::USB { class Transfer final : public AtomicRefCounted<Transfer> { public: - static ErrorOr<NonnullRefPtr<Transfer>> try_create(Pipe&, u16 length, Memory::Region& dma_buffer); + static ErrorOr<NonnullLockRefPtr<Transfer>> try_create(Pipe&, u16 length, Memory::Region& dma_buffer); Transfer() = delete; ~Transfer(); |