1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:17:35 +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:
Andreas Kling 2022-08-19 20:53:40 +02:00
parent e475263113
commit 11eee67b85
360 changed files with 1703 additions and 1672 deletions

View file

@ -23,16 +23,16 @@ namespace Kernel {
#define PATA_PRIMARY_IRQ 14
#define PATA_SECONDARY_IRQ 15
UNMAP_AFTER_INIT NonnullRefPtr<IDEChannel> IDEChannel::create(IDEController const& controller, IOAddressGroup io_group, ChannelType type)
UNMAP_AFTER_INIT NonnullLockRefPtr<IDEChannel> IDEChannel::create(IDEController const& controller, IOAddressGroup io_group, ChannelType type)
{
auto ata_identify_data_buffer = KBuffer::try_create_with_size("ATA Identify Page"sv, 4096, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value();
return adopt_ref(*new IDEChannel(controller, io_group, type, move(ata_identify_data_buffer)));
return adopt_lock_ref(*new IDEChannel(controller, io_group, type, move(ata_identify_data_buffer)));
}
UNMAP_AFTER_INIT NonnullRefPtr<IDEChannel> IDEChannel::create(IDEController const& controller, u8 irq, IOAddressGroup io_group, ChannelType type)
UNMAP_AFTER_INIT NonnullLockRefPtr<IDEChannel> IDEChannel::create(IDEController const& controller, u8 irq, IOAddressGroup io_group, ChannelType type)
{
auto ata_identify_data_buffer = KBuffer::try_create_with_size("ATA Identify Page"sv, 4096, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value();
return adopt_ref(*new IDEChannel(controller, irq, io_group, type, move(ata_identify_data_buffer)));
return adopt_lock_ref(*new IDEChannel(controller, irq, io_group, type, move(ata_identify_data_buffer)));
}
StringView IDEChannel::channel_type_string() const

View file

@ -18,10 +18,10 @@
#pragma once
#include <AK/Error.h>
#include <AK/RefPtr.h>
#include <Kernel/Arch/x86/IO.h>
#include <Kernel/Devices/Device.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Locking/Mutex.h>
#include <Kernel/Memory/PhysicalPage.h>
#include <Kernel/PhysicalAddress.h>
@ -103,8 +103,8 @@ public:
};
public:
static NonnullRefPtr<IDEChannel> create(IDEController const&, IOAddressGroup, ChannelType type);
static NonnullRefPtr<IDEChannel> create(IDEController const&, u8 irq, IOAddressGroup, ChannelType type);
static NonnullLockRefPtr<IDEChannel> create(IDEController const&, IOAddressGroup, ChannelType type);
static NonnullLockRefPtr<IDEChannel> create(IDEController const&, u8 irq, IOAddressGroup, ChannelType type);
virtual ~IDEChannel() override;

View file

@ -5,10 +5,10 @@
*/
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Sections.h>
#include <Kernel/Storage/ATA/ATADiskDevice.h>
#include <Kernel/Storage/ATA/GenericIDE/Channel.h>
@ -16,9 +16,9 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<IDEController> IDEController::initialize()
UNMAP_AFTER_INIT NonnullLockRefPtr<IDEController> IDEController::initialize()
{
return adopt_ref(*new IDEController());
return adopt_lock_ref(*new IDEController());
}
bool IDEController::reset()
@ -70,7 +70,7 @@ void IDEController::complete_current_request(AsyncDeviceRequest::RequestResult)
UNMAP_AFTER_INIT IDEController::IDEController() = default;
UNMAP_AFTER_INIT IDEController::~IDEController() = default;
RefPtr<StorageDevice> IDEController::device_by_channel_and_position(u32 index) const
LockRefPtr<StorageDevice> IDEController::device_by_channel_and_position(u32 index) const
{
switch (index) {
case 0:
@ -85,9 +85,9 @@ RefPtr<StorageDevice> IDEController::device_by_channel_and_position(u32 index) c
VERIFY_NOT_REACHED();
}
RefPtr<StorageDevice> IDEController::device(u32 index) const
LockRefPtr<StorageDevice> IDEController::device(u32 index) const
{
NonnullRefPtrVector<StorageDevice> connected_devices;
NonnullLockRefPtrVector<StorageDevice> connected_devices;
for (size_t index = 0; index < 4; index++) {
auto checked_device = device_by_channel_and_position(index);
if (checked_device.is_null())

View file

@ -7,8 +7,8 @@
#pragma once
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Storage/ATA/ATAController.h>
#include <Kernel/Storage/StorageDevice.h>
@ -18,10 +18,10 @@ class AsyncBlockDeviceRequest;
class IDEChannel;
class IDEController : public ATAController {
public:
static NonnullRefPtr<IDEController> initialize();
static NonnullLockRefPtr<IDEController> initialize();
virtual ~IDEController() override;
virtual RefPtr<StorageDevice> device(u32 index) const override final;
virtual LockRefPtr<StorageDevice> device(u32 index) const override final;
virtual bool reset() override final;
virtual bool shutdown() override final;
virtual size_t devices_count() const override final;
@ -31,7 +31,7 @@ public:
protected:
IDEController();
RefPtr<StorageDevice> device_by_channel_and_position(u32 index) const;
NonnullRefPtrVector<IDEChannel> m_channels;
LockRefPtr<StorageDevice> device_by_channel_and_position(u32 index) const;
NonnullLockRefPtrVector<IDEChannel> m_channels;
};
}

View file

@ -5,10 +5,10 @@
*/
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Sections.h>
#include <Kernel/Storage/ATA/ATADiskDevice.h>
#include <Kernel/Storage/ATA/GenericIDE/Channel.h>
@ -16,9 +16,9 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<ISAIDEController> ISAIDEController::initialize()
UNMAP_AFTER_INIT NonnullLockRefPtr<ISAIDEController> ISAIDEController::initialize()
{
return adopt_ref(*new ISAIDEController());
return adopt_lock_ref(*new ISAIDEController());
}
UNMAP_AFTER_INIT ISAIDEController::ISAIDEController()

View file

@ -7,8 +7,8 @@
#pragma once
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Storage/ATA/GenericIDE/Controller.h>
#include <Kernel/Storage/StorageDevice.h>
@ -18,12 +18,12 @@ class AsyncBlockDeviceRequest;
class ISAIDEController final : public IDEController {
public:
static NonnullRefPtr<ISAIDEController> initialize();
static NonnullLockRefPtr<ISAIDEController> initialize();
private:
ISAIDEController();
RefPtr<StorageDevice> device_by_channel_and_position(u32 index) const;
LockRefPtr<StorageDevice> device_by_channel_and_position(u32 index) const;
void initialize_channels();
};
}

View file

@ -5,10 +5,10 @@
*/
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Sections.h>
#include <Kernel/Storage/ATA/ATADiskDevice.h>
#include <Kernel/Storage/ATA/GenericIDE/Channel.h>
@ -16,9 +16,9 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<PCIIDEController> PCIIDEController::initialize(PCI::DeviceIdentifier const& device_identifier, bool force_pio)
UNMAP_AFTER_INIT NonnullLockRefPtr<PCIIDEController> PCIIDEController::initialize(PCI::DeviceIdentifier const& device_identifier, bool force_pio)
{
return adopt_ref(*new PCIIDEController(device_identifier, force_pio));
return adopt_lock_ref(*new PCIIDEController(device_identifier, force_pio));
}
UNMAP_AFTER_INIT PCIIDEController::PCIIDEController(PCI::DeviceIdentifier const& device_identifier, bool force_pio)

View file

@ -7,8 +7,8 @@
#pragma once
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Storage/ATA/GenericIDE/Controller.h>
#include <Kernel/Storage/StorageDevice.h>
@ -19,7 +19,7 @@ class AsyncBlockDeviceRequest;
class PCIIDEController final : public IDEController
, public PCI::Device {
public:
static NonnullRefPtr<PCIIDEController> initialize(PCI::DeviceIdentifier const&, bool force_pio);
static NonnullLockRefPtr<PCIIDEController> initialize(PCI::DeviceIdentifier const&, bool force_pio);
bool is_bus_master_capable() const;
bool is_pci_native_mode_enabled() const;
@ -29,7 +29,7 @@ private:
bool is_pci_native_mode_enabled_on_secondary_channel() const;
PCIIDEController(PCI::DeviceIdentifier const&, bool force_pio);
RefPtr<StorageDevice> device_by_channel_and_position(u32 index) const;
LockRefPtr<StorageDevice> device_by_channel_and_position(u32 index) const;
void initialize(bool force_pio);
void detect_disks();