1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:07:34 +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

@ -9,12 +9,12 @@
#include <AK/Atomic.h>
#include <AK/CircularQueue.h>
#include <AK/Error.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/RefPtr.h>
#include <AK/Time.h>
#include <AK/Types.h>
#include <Kernel/API/KeyCode.h>
#include <Kernel/API/MousePacket.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Library/NonnullLockRefPtrVector.h>
#include <Kernel/Locking/Spinlock.h>
#include <Kernel/Locking/SpinlockProtected.h>
#include <Kernel/UnixTypes.h>
@ -61,8 +61,8 @@ private:
size_t m_mouse_minor_number { 0 };
size_t m_keyboard_minor_number { 0 };
KeyboardClient* m_client { nullptr };
RefPtr<I8042Controller> m_i8042_controller;
NonnullRefPtrVector<HIDDevice> m_hid_devices;
LockRefPtr<I8042Controller> m_i8042_controller;
NonnullLockRefPtrVector<HIDDevice> m_hid_devices;
Spinlock m_client_lock { LockRank::None };
};

View file

@ -13,16 +13,16 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<I8042Controller> I8042Controller::initialize()
UNMAP_AFTER_INIT NonnullLockRefPtr<I8042Controller> I8042Controller::initialize()
{
return adopt_ref(*new I8042Controller());
return adopt_lock_ref(*new I8042Controller());
}
RefPtr<MouseDevice> I8042Controller::mouse() const
LockRefPtr<MouseDevice> I8042Controller::mouse() const
{
return m_mouse_device;
}
RefPtr<KeyboardDevice> I8042Controller::keyboard() const
LockRefPtr<KeyboardDevice> I8042Controller::keyboard() const
{
return m_keyboard_device;
}

View file

@ -77,7 +77,7 @@ protected:
{
}
NonnullRefPtr<I8042Controller> m_i8042_controller;
NonnullLockRefPtr<I8042Controller> m_i8042_controller;
};
class PS2KeyboardDevice;
@ -88,7 +88,7 @@ class I8042Controller final : public AtomicRefCounted<I8042Controller> {
friend class PS2MouseDevice;
public:
static NonnullRefPtr<I8042Controller> initialize();
static NonnullLockRefPtr<I8042Controller> initialize();
ErrorOr<void> detect_devices();
@ -132,8 +132,8 @@ public:
bool irq_process_input_buffer(HIDDevice::Type);
RefPtr<MouseDevice> mouse() const;
RefPtr<KeyboardDevice> keyboard() const;
LockRefPtr<MouseDevice> mouse() const;
LockRefPtr<KeyboardDevice> keyboard() const;
// Note: This function exists only for the initialization process of the controller
bool check_existence_via_probing(Badge<HIDManagement>);
@ -157,8 +157,8 @@ private:
bool m_first_port_available { false };
bool m_second_port_available { false };
bool m_is_dual_channel { false };
RefPtr<MouseDevice> m_mouse_device;
RefPtr<KeyboardDevice> m_keyboard_device;
LockRefPtr<MouseDevice> m_mouse_device;
LockRefPtr<KeyboardDevice> m_keyboard_device;
};
}

View file

@ -87,7 +87,7 @@ bool PS2KeyboardDevice::handle_irq(RegisterState const&)
return m_i8042_controller->irq_process_input_buffer(HIDDevice::Type::Keyboard);
}
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<PS2KeyboardDevice>> PS2KeyboardDevice::try_to_initialize(I8042Controller const& ps2_controller)
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<PS2KeyboardDevice>> PS2KeyboardDevice::try_to_initialize(I8042Controller const& ps2_controller)
{
auto keyboard_device = TRY(DeviceManagement::try_create_device<PS2KeyboardDevice>(ps2_controller));

View file

@ -23,7 +23,7 @@ class PS2KeyboardDevice final : public IRQHandler
friend class DeviceManagement;
public:
static ErrorOr<NonnullRefPtr<PS2KeyboardDevice>> try_to_initialize(I8042Controller const&);
static ErrorOr<NonnullLockRefPtr<PS2KeyboardDevice>> try_to_initialize(I8042Controller const&);
virtual ~PS2KeyboardDevice() override;
ErrorOr<void> initialize();

View file

@ -175,7 +175,7 @@ ErrorOr<void> PS2MouseDevice::set_sample_rate(u8 rate)
return {};
}
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<PS2MouseDevice>> PS2MouseDevice::try_to_initialize(I8042Controller const& ps2_controller)
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<PS2MouseDevice>> PS2MouseDevice::try_to_initialize(I8042Controller const& ps2_controller)
{
auto mouse_device = TRY(DeviceManagement::try_create_device<PS2MouseDevice>(ps2_controller));
TRY(mouse_device->initialize());

View file

@ -20,7 +20,7 @@ class PS2MouseDevice : public IRQHandler
friend class DeviceManagement;
public:
static ErrorOr<NonnullRefPtr<PS2MouseDevice>> try_to_initialize(I8042Controller const&);
static ErrorOr<NonnullLockRefPtr<PS2MouseDevice>> try_to_initialize(I8042Controller const&);
ErrorOr<void> initialize();
virtual ~PS2MouseDevice() override;

View file

@ -11,7 +11,7 @@
namespace Kernel {
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<VMWareMouseDevice>> VMWareMouseDevice::try_to_initialize(I8042Controller const& ps2_controller)
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<VMWareMouseDevice>> VMWareMouseDevice::try_to_initialize(I8042Controller const& ps2_controller)
{
// FIXME: return the correct error
if (!VMWareBackdoor::the())

View file

@ -18,7 +18,7 @@ namespace Kernel {
class VMWareMouseDevice final : public PS2MouseDevice {
public:
friend class DeviceManagement;
static ErrorOr<NonnullRefPtr<VMWareMouseDevice>> try_to_initialize(I8042Controller const&);
static ErrorOr<NonnullLockRefPtr<VMWareMouseDevice>> try_to_initialize(I8042Controller const&);
virtual ~VMWareMouseDevice() override;
// ^I8042Device