1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:18:13 +00:00

AK+Kernel: Add AK::AtomicRefCounted and use everywhere in the kernel

Instead of having two separate implementations of AK::RefCounted, one
for userspace and one for kernelspace, there is now RefCounted and
AtomicRefCounted.
This commit is contained in:
Andreas Kling 2022-08-19 17:26:07 +02:00
parent 4889eb019a
commit e475263113
45 changed files with 81 additions and 94 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -15,9 +15,9 @@
namespace AK { namespace AK {
class RefCountedBase { class AtomicRefCountedBase {
AK_MAKE_NONCOPYABLE(RefCountedBase); AK_MAKE_NONCOPYABLE(AtomicRefCountedBase);
AK_MAKE_NONMOVABLE(RefCountedBase); AK_MAKE_NONMOVABLE(AtomicRefCountedBase);
public: public:
using RefCountType = unsigned int; using RefCountType = unsigned int;
@ -48,8 +48,8 @@ public:
} }
protected: protected:
RefCountedBase() = default; AtomicRefCountedBase() = default;
~RefCountedBase() ~AtomicRefCountedBase()
{ {
VERIFY(m_ref_count.load(AK::MemoryOrder::memory_order_relaxed) == 0); VERIFY(m_ref_count.load(AK::MemoryOrder::memory_order_relaxed) == 0);
} }
@ -65,7 +65,7 @@ protected:
}; };
template<typename T> template<typename T>
class RefCounted : public RefCountedBase { class AtomicRefCounted : public AtomicRefCountedBase {
public: public:
bool unref() const bool unref() const
{ {
@ -83,5 +83,5 @@ public:
} }
using AK::RefCounted; using AK::AtomicRefCounted;
using AK::RefCountedBase; using AK::AtomicRefCountedBase;

View file

@ -6,15 +6,11 @@
#pragma once #pragma once
#ifdef KERNEL #include <AK/Assertions.h>
# include <Kernel/Library/ThreadSafeRefCounted.h> #include <AK/Checked.h>
#else #include <AK/Noncopyable.h>
#include <AK/Platform.h>
# include <AK/Assertions.h> #include <AK/StdLibExtras.h>
# include <AK/Checked.h>
# include <AK/Noncopyable.h>
# include <AK/Platform.h>
# include <AK/StdLibExtras.h>
namespace AK { namespace AK {
@ -67,7 +63,7 @@ public:
if (new_ref_count == 0) { if (new_ref_count == 0) {
if constexpr (requires { that->will_be_destroyed(); }) if constexpr (requires { that->will_be_destroyed(); })
that->will_be_destroyed(); that->will_be_destroyed();
delete static_cast<const T*>(this); delete static_cast<T const*>(this);
return true; return true;
} }
return false; return false;
@ -78,5 +74,3 @@ public:
using AK::RefCounted; using AK::RefCounted;
using AK::RefCountedBase; using AK::RefCountedBase;
#endif

View file

@ -6,14 +6,14 @@
#pragma once #pragma once
#include <AK/RefCounted.h> #include <AK/AtomicRefCounted.h>
#include <AK/Types.h> #include <AK/Types.h>
namespace Kernel { namespace Kernel {
class GenericInterruptHandler; class GenericInterruptHandler;
class IRQController : public RefCounted<IRQController> { class IRQController : public AtomicRefCounted<IRQController> {
public: public:
virtual ~IRQController() = default; virtual ~IRQController() = default;

View file

@ -6,7 +6,7 @@
#pragma once #pragma once
#include <AK/RefCounted.h> #include <AK/AtomicRefCounted.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Interrupts/GenericInterruptHandler.h> #include <Kernel/Interrupts/GenericInterruptHandler.h>
@ -19,7 +19,7 @@ enum class IRQControllerType {
i82093AA = 2 /* Intel 82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC) */ i82093AA = 2 /* Intel 82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC) */
}; };
class IRQController : public RefCounted<IRQController> { class IRQController : public AtomicRefCounted<IRQController> {
public: public:
virtual ~IRQController() = default; virtual ~IRQController() = default;

View file

@ -9,7 +9,6 @@
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/NonnullOwnPtr.h> #include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Arch/x86/IRQController.h> #include <Kernel/Arch/x86/IRQController.h>

View file

@ -6,14 +6,14 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Error.h> #include <AK/Error.h>
#include <AK/RefCounted.h>
#include <Kernel/Bus/USB/USBDevice.h> #include <Kernel/Bus/USB/USBDevice.h>
#include <Kernel/Bus/USB/USBTransfer.h> #include <Kernel/Bus/USB/USBTransfer.h>
namespace Kernel::USB { namespace Kernel::USB {
class USBController : public RefCounted<USBController> { class USBController : public AtomicRefCounted<USBController> {
public: public:
virtual ~USBController() = default; virtual ~USBController() = default;

View file

@ -27,7 +27,7 @@ class USBConfiguration;
// //
// https://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_113_Simplified%20Description%20of%20USB%20Device%20Enumeration.pdf // https://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_113_Simplified%20Description%20of%20USB%20Device%20Enumeration.pdf
class Hub; class Hub;
class Device : public RefCounted<Device> { class Device : public AtomicRefCounted<Device> {
public: public:
enum class DeviceSpeed : u8 { enum class DeviceSpeed : u8 {
FullSpeed = 0, FullSpeed = 0,

View file

@ -6,7 +6,6 @@
#pragma once #pragma once
#include <AK/RefCounted.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Bus/USB/USBDevice.h> #include <Kernel/Bus/USB/USBDevice.h>

View file

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <Kernel/Bus/USB/PacketTypes.h> #include <Kernel/Bus/USB/PacketTypes.h>
@ -17,7 +18,7 @@
// TODO: Callback stuff in this class please! // TODO: Callback stuff in this class please!
namespace Kernel::USB { namespace Kernel::USB {
class Transfer : public RefCounted<Transfer> { class Transfer final : public AtomicRefCounted<Transfer> {
public: public:
static ErrorOr<NonnullRefPtr<Transfer>> try_create(Pipe&, u16 length, Memory::Region& dma_buffer); static ErrorOr<NonnullRefPtr<Transfer>> try_create(Pipe&, u16 length, Memory::Region& dma_buffer);

View file

@ -14,7 +14,7 @@
namespace Kernel::VirtIO { namespace Kernel::VirtIO {
class Console class Console
: public VirtIO::Device : public VirtIO::Device
, public RefCounted<Console> { , public AtomicRefCounted<Console> {
friend VirtIO::ConsolePort; friend VirtIO::ConsolePort;
public: public:

View file

@ -6,7 +6,7 @@
#pragma once #pragma once
#include <AK/RefCounted.h> #include <AK/AtomicRefCounted.h>
#include <Kernel/Bus/VirtIO/Device.h> #include <Kernel/Bus/VirtIO/Device.h>
#include <Kernel/Devices/CharacterDevice.h> #include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/Random.h> #include <Kernel/Random.h>
@ -16,7 +16,7 @@ namespace Kernel::VirtIO {
#define REQUESTQ 0 #define REQUESTQ 0
class RNG final class RNG final
: public RefCounted<RNG> : public AtomicRefCounted<RNG>
, public VirtIO::Device { , public VirtIO::Device {
public: public:
static NonnullRefPtr<RNG> must_create(PCI::DeviceIdentifier const&); static NonnullRefPtr<RNG> must_create(PCI::DeviceIdentifier const&);

View file

@ -20,7 +20,7 @@ class Device;
extern WorkQueue* g_io_work; extern WorkQueue* g_io_work;
class AsyncDeviceRequest : public RefCounted<AsyncDeviceRequest> { class AsyncDeviceRequest : public AtomicRefCounted<AsyncDeviceRequest> {
AK_MAKE_NONCOPYABLE(AsyncDeviceRequest); AK_MAKE_NONCOPYABLE(AsyncDeviceRequest);
AK_MAKE_NONMOVABLE(AsyncDeviceRequest); AK_MAKE_NONMOVABLE(AsyncDeviceRequest);

View file

@ -23,7 +23,7 @@ namespace Kernel {
class AudioManagement; class AudioManagement;
class AudioController class AudioController
: public RefCounted<AudioController> : public AtomicRefCounted<AudioController>
, public Weakable<AudioController> { , public Weakable<AudioController> {
friend class AudioManagement; friend class AudioManagement;

View file

@ -6,7 +6,7 @@
#pragma once #pragma once
#include <AK/RefCounted.h> #include <AK/AtomicRefCounted.h>
#include <Kernel/Devices/HID/KeyboardDevice.h> #include <Kernel/Devices/HID/KeyboardDevice.h>
#include <Kernel/Devices/HID/MouseDevice.h> #include <Kernel/Devices/HID/MouseDevice.h>
#include <Kernel/Locking/Spinlock.h> #include <Kernel/Locking/Spinlock.h>
@ -83,7 +83,7 @@ protected:
class PS2KeyboardDevice; class PS2KeyboardDevice;
class PS2MouseDevice; class PS2MouseDevice;
class HIDManagement; class HIDManagement;
class I8042Controller : public RefCounted<I8042Controller> { class I8042Controller final : public AtomicRefCounted<I8042Controller> {
friend class PS2KeyboardDevice; friend class PS2KeyboardDevice;
friend class PS2MouseDevice; friend class PS2MouseDevice;

View file

@ -6,9 +6,9 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Error.h> #include <AK/Error.h>
#include <AK/NonnullRefPtr.h> #include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <AK/Weakable.h> #include <AK/Weakable.h>
@ -71,10 +71,10 @@ public:
// - Should create a Region in the Process and return it if successful. // - Should create a Region in the Process and return it if successful.
class File class File
: public RefCounted<File> : public AtomicRefCounted<File>
, public Weakable<File> { , public Weakable<File> {
public: public:
virtual bool unref() const { return RefCounted<File>::unref(); } virtual bool unref() const { return AtomicRefCounted<File>::unref(); }
virtual void will_be_destroyed() { } virtual void will_be_destroyed() { }
virtual ~File(); virtual ~File();

View file

@ -6,8 +6,8 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Error.h> #include <AK/Error.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <Kernel/FileSystem/InodeIdentifier.h> #include <Kernel/FileSystem/InodeIdentifier.h>
@ -18,7 +18,7 @@
namespace Kernel { namespace Kernel {
class FileSystem : public RefCounted<FileSystem> { class FileSystem : public AtomicRefCounted<FileSystem> {
friend class Inode; friend class Inode;
public: public:

View file

@ -283,7 +283,7 @@ class ISO9660FS final : public BlockBasedFileSystem {
friend ISO9660DirectoryIterator; friend ISO9660DirectoryIterator;
public: public:
struct DirectoryEntry : public RefCounted<DirectoryEntry> { struct DirectoryEntry final : public AtomicRefCounted<DirectoryEntry> {
u32 extent { 0 }; u32 extent { 0 };
u32 length { 0 }; u32 length { 0 };

View file

@ -6,8 +6,8 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Badge.h> #include <AK/Badge.h>
#include <AK/RefCounted.h>
#include <Kernel/FileSystem/FIFO.h> #include <Kernel/FileSystem/FIFO.h>
#include <Kernel/FileSystem/Inode.h> #include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/InodeMetadata.h> #include <Kernel/FileSystem/InodeMetadata.h>
@ -22,7 +22,7 @@ public:
virtual ~OpenFileDescriptionData() = default; virtual ~OpenFileDescriptionData() = default;
}; };
class OpenFileDescription : public RefCounted<OpenFileDescription> { class OpenFileDescription final : public AtomicRefCounted<OpenFileDescription> {
public: public:
static ErrorOr<NonnullRefPtr<OpenFileDescription>> try_create(Custody&); static ErrorOr<NonnullRefPtr<OpenFileDescription>> try_create(Custody&);
static ErrorOr<NonnullRefPtr<OpenFileDescription>> try_create(File&); static ErrorOr<NonnullRefPtr<OpenFileDescription>> try_create(File&);

View file

@ -69,7 +69,7 @@ private:
mutable Spinlock m_lock { LockRank::None }; mutable Spinlock m_lock { LockRank::None };
}; };
struct ReceiveCompletion : public RefCounted<ReceiveCompletion> { struct ReceiveCompletion final : public AtomicRefCounted<ReceiveCompletion> {
mutable Spinlock lock { LockRank::None }; mutable Spinlock lock { LockRank::None };
bool completed { false }; bool completed { false };
const u16 tag; const u16 tag;

View file

@ -6,9 +6,9 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Error.h> #include <AK/Error.h>
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Types.h> #include <AK/Types.h>
@ -24,7 +24,7 @@ struct SysFSInodeData : public OpenFileDescriptionData {
}; };
class SysFSDirectory; class SysFSDirectory;
class SysFSComponent : public RefCounted<SysFSComponent> { class SysFSComponent : public AtomicRefCounted<SysFSComponent> {
friend class SysFSDirectory; friend class SysFSDirectory;
public: public:

View file

@ -6,9 +6,7 @@
#pragma once #pragma once
#include <AK/RefCounted.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <AK/Vector.h>
#include <Kernel/PhysicalAddress.h> #include <Kernel/PhysicalAddress.h>
namespace Kernel::ACPI { namespace Kernel::ACPI {

View file

@ -6,16 +6,14 @@
#pragma once #pragma once
#include <AK/Atomic.h> #include <AK/AtomicRefCounted.h>
#include <AK/RefCounted.h>
#include <Kernel/Locking/Spinlock.h> #include <Kernel/Locking/Spinlock.h>
#include <Kernel/Memory/VMObject.h>
#include <Kernel/Thread.h> #include <Kernel/Thread.h>
namespace Kernel { namespace Kernel {
class FutexQueue final class FutexQueue final
: public RefCounted<FutexQueue> : public AtomicRefCounted<FutexQueue>
, public Thread::BlockerSet { , public Thread::BlockerSet {
public: public:
FutexQueue(); FutexQueue();

View file

@ -6,13 +6,13 @@
#pragma once #pragma once
#include <AK/RefCounted.h> #include <AK/AtomicRefCounted.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Graphics/GenericGraphicsAdapter.h> #include <Kernel/Graphics/GenericGraphicsAdapter.h>
namespace Kernel::Graphics { namespace Kernel::Graphics {
class Console : public RefCounted<Console> { class Console : public AtomicRefCounted<Console> {
public: public:
// Stanadard VGA text mode colors // Stanadard VGA text mode colors
enum Color : u8 { enum Color : u8 {

View file

@ -6,7 +6,6 @@
#pragma once #pragma once
#include <AK/RefCounted.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Graphics/Console/Console.h> #include <Kernel/Graphics/Console/Console.h>
#include <Kernel/PhysicalAddress.h> #include <Kernel/PhysicalAddress.h>

View file

@ -6,7 +6,6 @@
#pragma once #pragma once
#include <AK/RefCounted.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Graphics/Console/Console.h> #include <Kernel/Graphics/Console/Console.h>
#include <Kernel/Locking/Spinlock.h> #include <Kernel/Locking/Spinlock.h>

View file

@ -14,7 +14,7 @@
namespace Kernel { namespace Kernel {
class GenericGraphicsAdapter class GenericGraphicsAdapter
: public RefCounted<GenericGraphicsAdapter> : public AtomicRefCounted<GenericGraphicsAdapter>
, public Weakable<GenericGraphicsAdapter> { , public Weakable<GenericGraphicsAdapter> {
public: public:
virtual ~GenericGraphicsAdapter() = default; virtual ~GenericGraphicsAdapter() = default;

View file

@ -100,7 +100,7 @@ public:
private: private:
VirtIOGPU3DDevice(VirtIOGraphicsAdapter const& graphics_adapter, NonnullOwnPtr<Memory::Region> transfer_buffer_region); VirtIOGPU3DDevice(VirtIOGraphicsAdapter const& graphics_adapter, NonnullOwnPtr<Memory::Region> transfer_buffer_region);
class PerContextState : public RefCounted<PerContextState> { class PerContextState final : public AtomicRefCounted<PerContextState> {
public: public:
static ErrorOr<RefPtr<PerContextState>> try_create(Graphics::VirtIOGPU::ContextID context_id) static ErrorOr<RefPtr<PerContextState>> try_create(Graphics::VirtIOGPU::ContextID context_id)
{ {

View file

@ -6,7 +6,7 @@
#pragma once #pragma once
#include <AK/RefCounted.h> #include <AK/AtomicRefCounted.h>
namespace Kernel { namespace Kernel {
@ -21,7 +21,7 @@ enum class LockType {
}; };
template<typename T, LockType Lock> template<typename T, LockType Lock>
class ListedRefCounted : public RefCountedBase { class ListedRefCounted : public AtomicRefCountedBase {
public: public:
bool unref() const bool unref() const
{ {

View file

@ -168,7 +168,7 @@ template<typename T>
template<typename U> template<typename U>
inline ErrorOr<WeakPtr<U>> Weakable<T>::try_make_weak_ptr() const inline ErrorOr<WeakPtr<U>> Weakable<T>::try_make_weak_ptr() const
{ {
if constexpr (IsBaseOf<RefCountedBase, T>) { if constexpr (IsBaseOf<AtomicRefCountedBase, T>) {
// Checking m_being_destroyed isn't sufficient when dealing with // Checking m_being_destroyed isn't sufficient when dealing with
// a RefCounted type.The reference count will drop to 0 before the // a RefCounted type.The reference count will drop to 0 before the
// destructor is invoked and revoke_weak_ptrs is called. So, try // destructor is invoked and revoke_weak_ptrs is called. So, try
@ -192,7 +192,7 @@ inline ErrorOr<WeakPtr<U>> Weakable<T>::try_make_weak_ptr() const
WeakPtr<U> weak_ptr(m_link); WeakPtr<U> weak_ptr(m_link);
if constexpr (IsBaseOf<RefCountedBase, T>) { if constexpr (IsBaseOf<AtomicRefCountedBase, T>) {
// Now drop the reference we temporarily added // Now drop the reference we temporarily added
if (static_cast<const T*>(this)->unref()) { if (static_cast<const T*>(this)->unref()) {
// We just dropped the last reference, which should have called // We just dropped the last reference, which should have called

View file

@ -8,7 +8,7 @@
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <AK/Atomic.h> #include <AK/Atomic.h>
#include <AK/RefCounted.h> #include <AK/AtomicRefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/Processor.h>
@ -21,7 +21,7 @@ class Weakable;
template<typename T> template<typename T>
class WeakPtr; class WeakPtr;
class WeakLink : public RefCounted<WeakLink> { class WeakLink final : public AtomicRefCounted<WeakLink> {
template<typename T> template<typename T>
friend class Weakable; friend class Weakable;
template<typename T> template<typename T>
@ -30,7 +30,7 @@ class WeakLink : public RefCounted<WeakLink> {
public: public:
template<typename T, typename PtrTraits = RefPtrTraits<T>> template<typename T, typename PtrTraits = RefPtrTraits<T>>
RefPtr<T, PtrTraits> strong_ref() const RefPtr<T, PtrTraits> strong_ref() const
requires(IsBaseOf<RefCountedBase, T>) requires(IsBaseOf<AtomicRefCountedBase, T>)
{ {
RefPtr<T, PtrTraits> ref; RefPtr<T, PtrTraits> ref;

View file

@ -63,7 +63,7 @@ private:
Bitmap m_cow_map; Bitmap m_cow_map;
// AnonymousVMObject shares committed COW pages with cloned children (happens on fork) // AnonymousVMObject shares committed COW pages with cloned children (happens on fork)
class SharedCommittedCowPages : public RefCounted<SharedCommittedCowPages> { class SharedCommittedCowPages final : public AtomicRefCounted<SharedCommittedCowPages> {
AK_MAKE_NONCOPYABLE(SharedCommittedCowPages); AK_MAKE_NONCOPYABLE(SharedCommittedCowPages);
public: public:

View file

@ -6,10 +6,10 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Badge.h> #include <AK/Badge.h>
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/IntrusiveRedBlackTree.h> #include <AK/IntrusiveRedBlackTree.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <Kernel/Forward.h> #include <Kernel/Forward.h>
#include <Kernel/Locking/Spinlock.h> #include <Kernel/Locking/Spinlock.h>
@ -17,7 +17,7 @@
namespace Kernel::Memory { namespace Kernel::Memory {
class PageDirectory : public RefCounted<PageDirectory> { class PageDirectory final : public AtomicRefCounted<PageDirectory> {
friend class MemoryManager; friend class MemoryManager;
public: public:

View file

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <Kernel/Devices/BlockDevice.h> #include <Kernel/Devices/BlockDevice.h>
#include <Kernel/Memory/AnonymousVMObject.h> #include <Kernel/Memory/AnonymousVMObject.h>
@ -16,7 +17,7 @@ namespace Kernel::Memory {
// A Scatter-Gather List type that owns its buffers // A Scatter-Gather List type that owns its buffers
class ScatterGatherList : public RefCounted<ScatterGatherList> { class ScatterGatherList final : public AtomicRefCounted<ScatterGatherList> {
public: public:
static RefPtr<ScatterGatherList> try_create(AsyncBlockDeviceRequest&, Span<NonnullRefPtr<PhysicalPage>> allocated_pages, size_t device_block_size); static RefPtr<ScatterGatherList> try_create(AsyncBlockDeviceRequest&, Span<NonnullRefPtr<PhysicalPage>> allocated_pages, size_t device_block_size);
VMObject const& vmobject() const { return m_vm_object; } VMObject const& vmobject() const { return m_vm_object; }

View file

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/IntrusiveList.h> #include <AK/IntrusiveList.h>
@ -27,7 +28,7 @@ class NetworkAdapter;
using NetworkByteBuffer = AK::Detail::ByteBuffer<1500>; using NetworkByteBuffer = AK::Detail::ByteBuffer<1500>;
struct PacketWithTimestamp : public RefCounted<PacketWithTimestamp> { struct PacketWithTimestamp final : public AtomicRefCounted<PacketWithTimestamp> {
PacketWithTimestamp(NonnullOwnPtr<KBuffer> buffer, Time timestamp) PacketWithTimestamp(NonnullOwnPtr<KBuffer> buffer, Time timestamp)
: buffer(move(buffer)) : buffer(move(buffer))
, timestamp(timestamp) , timestamp(timestamp)
@ -41,7 +42,8 @@ struct PacketWithTimestamp : public RefCounted<PacketWithTimestamp> {
IntrusiveListNode<PacketWithTimestamp, RefPtr<PacketWithTimestamp>> packet_node; IntrusiveListNode<PacketWithTimestamp, RefPtr<PacketWithTimestamp>> packet_node;
}; };
class NetworkAdapter : public RefCounted<NetworkAdapter> class NetworkAdapter
: public AtomicRefCounted<NetworkAdapter>
, public Weakable<NetworkAdapter> { , public Weakable<NetworkAdapter> {
public: public:
static constexpr i32 LINKSPEED_INVALID = -1; static constexpr i32 LINKSPEED_INVALID = -1;

View file

@ -14,7 +14,7 @@
namespace Kernel { namespace Kernel {
struct Route : public RefCounted<Route> { struct Route final : public AtomicRefCounted<Route> {
Route(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, u16 flags, NonnullRefPtr<NetworkAdapter> adapter) Route(IPv4Address const& destination, IPv4Address const& gateway, IPv4Address const& netmask, u16 flags, NonnullRefPtr<NetworkAdapter> adapter)
: destination(destination) : destination(destination)
, gateway(gateway) , gateway(gateway)

View file

@ -8,7 +8,6 @@
#include <AK/Error.h> #include <AK/Error.h>
#include <AK/NonnullRefPtrVector.h> #include <AK/NonnullRefPtrVector.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/Time.h> #include <AK/Time.h>
#include <Kernel/FileSystem/File.h> #include <Kernel/FileSystem/File.h>

View file

@ -6,9 +6,9 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Error.h> #include <AK/Error.h>
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/FileSystem/File.h> #include <Kernel/FileSystem/File.h>
@ -66,7 +66,7 @@ private:
NonnullRefPtr<ProcFSRootDirectory> m_root_directory; NonnullRefPtr<ProcFSRootDirectory> m_root_directory;
}; };
class ProcFSExposedComponent : public RefCounted<ProcFSExposedComponent> { class ProcFSExposedComponent : public AtomicRefCounted<ProcFSExposedComponent> {
public: public:
StringView name() const { return m_name->view(); } StringView name() const { return m_name->view(); }
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); } virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); }

View file

@ -6,8 +6,8 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/IntrusiveList.h> #include <AK/IntrusiveList.h>
#include <AK/RefCounted.h>
#include <AK/Weakable.h> #include <AK/Weakable.h>
#include <Kernel/Locking/SpinlockProtected.h> #include <Kernel/Locking/SpinlockProtected.h>
#include <Kernel/UnixTypes.h> #include <Kernel/UnixTypes.h>
@ -15,7 +15,7 @@
namespace Kernel { namespace Kernel {
class ProcessGroup class ProcessGroup
: public RefCounted<ProcessGroup> : public AtomicRefCounted<ProcessGroup>
, public Weakable<ProcessGroup> { , public Weakable<ProcessGroup> {
AK_MAKE_NONMOVABLE(ProcessGroup); AK_MAKE_NONMOVABLE(ProcessGroup);

View file

@ -32,7 +32,7 @@ class AsyncBlockDeviceRequest;
class AHCIInterruptHandler; class AHCIInterruptHandler;
class AHCIPort class AHCIPort
: public RefCounted<AHCIPort> : public AtomicRefCounted<AHCIPort>
, public Weakable<AHCIPort> { , public Weakable<AHCIPort> {
friend class AHCIController; friend class AHCIController;

View file

@ -13,7 +13,7 @@ namespace Kernel {
class AsyncBlockDeviceRequest; class AsyncBlockDeviceRequest;
class ATAPort class ATAPort
: public RefCounted<ATAPort> : public AtomicRefCounted<ATAPort>
, public Weakable<ATAPort> { , public Weakable<ATAPort> {
friend class ATAPortInterruptDisabler; friend class ATAPortInterruptDisabler;

View file

@ -10,7 +10,6 @@
#include <AK/NonnullRefPtr.h> #include <AK/NonnullRefPtr.h>
#include <AK/NonnullRefPtrVector.h> #include <AK/NonnullRefPtrVector.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Locking/Spinlock.h> #include <Kernel/Locking/Spinlock.h>

View file

@ -6,10 +6,10 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/NonnullRefPtr.h> #include <AK/NonnullRefPtr.h>
#include <AK/NonnullRefPtrVector.h> #include <AK/NonnullRefPtrVector.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Bus/PCI/Device.h> #include <Kernel/Bus/PCI/Device.h>
@ -27,9 +27,9 @@ struct DoorbellRegister {
}; };
class AsyncBlockDeviceRequest; class AsyncBlockDeviceRequest;
class NVMeQueue : public RefCounted<NVMeQueue> { class NVMeQueue : public AtomicRefCounted<NVMeQueue> {
public: public:
static ErrorOr<NonnullRefPtr<NVMeQueue>> try_create(u16 qid, Optional<u8> irq, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs); static ErrorOr<NonnullRefPtr<NVMeQueue>> try_create(u16 qid, Optional<u8> irq, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<DoorbellRegister volatile> db_regs);
bool is_admin_queue() { return m_admin_queue; }; bool is_admin_queue() { return m_admin_queue; };
u16 submit_sync_sqe(NVMeSubmission&); u16 submit_sync_sqe(NVMeSubmission&);
void read(AsyncBlockDeviceRequest& request, u16 nsid, u64 index, u32 count); void read(AsyncBlockDeviceRequest& request, u16 nsid, u64 index, u32 count);
@ -43,7 +43,7 @@ protected:
{ {
m_db_regs->sq_tail = m_sq_tail; m_db_regs->sq_tail = m_sq_tail;
} }
NVMeQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs); NVMeQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<DoorbellRegister volatile> db_regs);
private: private:
bool cqe_available(); bool cqe_available();
@ -75,7 +75,7 @@ private:
OwnPtr<Memory::Region> m_sq_dma_region; OwnPtr<Memory::Region> m_sq_dma_region;
NonnullRefPtrVector<Memory::PhysicalPage> m_sq_dma_page; NonnullRefPtrVector<Memory::PhysicalPage> m_sq_dma_page;
Span<NVMeCompletion> m_cqe_array; Span<NVMeCompletion> m_cqe_array;
Memory::TypedMapping<volatile DoorbellRegister> m_db_regs; Memory::TypedMapping<DoorbellRegister volatile> m_db_regs;
NonnullRefPtr<Memory::PhysicalPage> m_rw_dma_page; NonnullRefPtr<Memory::PhysicalPage> m_rw_dma_page;
}; };
} }

View file

@ -21,7 +21,7 @@ namespace Kernel {
class AsyncBlockDeviceRequest; class AsyncBlockDeviceRequest;
class StorageDevice; class StorageDevice;
class StorageController : public RefCounted<StorageController> { class StorageController : public AtomicRefCounted<StorageController> {
public: public:
virtual ~StorageController() = default; virtual ~StorageController() = default;

View file

@ -6,8 +6,8 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/RefCounted.h>
#include <Kernel/Interrupts/IRQHandler.h> #include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Time/TimeManagement.h> #include <Kernel/Time/TimeManagement.h>
@ -23,8 +23,7 @@ enum class HardwareTimerType {
template<typename InterruptHandlerType> template<typename InterruptHandlerType>
class HardwareTimer; class HardwareTimer;
class HardwareTimerBase class HardwareTimerBase : public AtomicRefCounted<HardwareTimerBase> {
: public RefCounted<HardwareTimerBase> {
public: public:
virtual ~HardwareTimerBase() = default; virtual ~HardwareTimerBase() = default;

View file

@ -6,11 +6,11 @@
#pragma once #pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/IntrusiveList.h> #include <AK/IntrusiveList.h>
#include <AK/NonnullRefPtr.h> #include <AK/NonnullRefPtr.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/RefCounted.h>
#include <AK/Time.h> #include <AK/Time.h>
#include <Kernel/Time/TimeManagement.h> #include <Kernel/Time/TimeManagement.h>
@ -18,7 +18,7 @@ namespace Kernel {
AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, TimerId); AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, TimerId);
class Timer : public RefCounted<Timer> { class Timer final : public AtomicRefCounted<Timer> {
friend class TimerQueue; friend class TimerQueue;
public: public: