Skip to content

Commit

Permalink
Kernel: Make all Spinlocks use u8 for storage, remove template
Browse files Browse the repository at this point in the history
The default template argument is only used in one place, and it
looks like it was probably just an oversight. The rest of the Kernel
code all uses u8 as the type. So lets make that the default and remove
the unused template argument, as there doesn't seem to be a reason to
allow the size to be customizable.
  • Loading branch information
bgianfo authored and awesomekling committed Sep 5, 2021
1 parent 5905d2e commit bb58a4d
Show file tree
Hide file tree
Showing 38 changed files with 56 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Documentation/Kernel/AHCILocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ return true;
This lock doesn't disable interrupts at all, and if it is already in use, the scheduler will simply yield away from that section until it tries to lock it again.
### Hard lock - `SpinLock<u8>`
### Hard lock - `Spinlock`
A hard lock is essentially a lock that is used in critical sections in the kernel. We use it with a `ScopedSpinLock` class, to create a scoped locking of that lock:
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Bus/PCI/MMIOAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MMIOAccess : public Access {
PhysicalAddress determine_memory_mapped_bus_region(u32 segment, u8 bus) const;
void map_bus_region(u32, u8);
VirtualAddress get_device_configuration_space(Address address);
Spinlock<u8> m_access_lock;
Spinlock m_access_lock;
u8 m_mapped_bus { 0 };
OwnPtr<Memory::Region> m_mapped_region;

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Bus/USB/SysFSUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SysFSUSBBusDirectory final : public SysFSDirectory {
RefPtr<SysFSUSBDeviceInformation> device_node_for(USB::Device& device);

IntrusiveList<SysFSUSBDeviceInformation, RefPtr<SysFSUSBDeviceInformation>, &SysFSUSBDeviceInformation::m_list_node> m_device_nodes;
mutable Spinlock<u8> m_lock;
mutable Spinlock m_lock;
};

}
4 changes: 2 additions & 2 deletions Kernel/Bus/VirtIO/Queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Queue {
QueueChain pop_used_buffer_chain(size_t& used);
void discard_used_buffers();

Spinlock<u8>& lock() { return m_lock; }
Spinlock& lock() { return m_lock; }

bool should_notify() const;

Expand Down Expand Up @@ -94,7 +94,7 @@ class Queue {
OwnPtr<QueueDriver> m_driver { nullptr };
OwnPtr<QueueDevice> m_device { nullptr };
OwnPtr<Memory::Region> m_queue_region;
Spinlock<u8> m_lock;
Spinlock m_lock;

friend class QueueChain;
};
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Devices/AsyncDeviceRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AsyncDeviceRequest : public RefCounted<AsyncDeviceRequest> {

[[nodiscard]] RequestWaitResult wait(Time* = nullptr);

void do_start(SpinlockLocker<Spinlock<u8>>&& requests_lock)
void do_start(SpinlockLocker<Spinlock>&& requests_lock)
{
if (is_completed_result(m_result))
return;
Expand Down Expand Up @@ -150,7 +150,7 @@ class AsyncDeviceRequest : public RefCounted<AsyncDeviceRequest> {
WaitQueue m_queue;
NonnullRefPtr<Process> m_process;
void* m_private { nullptr };
mutable Spinlock<u8> m_lock;
mutable Spinlock m_lock;
};

}
2 changes: 1 addition & 1 deletion Kernel/Devices/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Device : public File {
UserID m_uid { 0 };
GroupID m_gid { 0 };

Spinlock<u8> m_requests_lock;
Spinlock m_requests_lock;
DoublyLinkedList<RefPtr<AsyncDeviceRequest>> m_requests;
};

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/HID/I8042Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class I8042Controller : public RefCounted<I8042Controller> {
void do_wait_then_write(u8 port, u8 data);
u8 do_wait_then_read(u8 port);

Spinlock<u8> m_lock;
Spinlock m_lock;
bool m_first_port_available { false };
bool m_second_port_available { false };
bool m_is_dual_channel { false };
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/HID/KeyboardDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class KeyboardDevice : public HIDDevice {

protected:
KeyboardDevice();
mutable Spinlock<u8> m_queue_lock;
mutable Spinlock m_queue_lock;
CircularQueue<Event, 16> m_queue;
// ^CharacterDevice
virtual StringView class_name() const override { return "KeyboardDevice"; }
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/HID/MouseDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MouseDevice : public HIDDevice {
// ^CharacterDevice
virtual StringView class_name() const override { return "MouseDevice"; }

mutable Spinlock<u8> m_queue_lock;
mutable Spinlock m_queue_lock;
CircularQueue<MousePacket, 100> m_queue;
};

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/KCOVInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class KCOVInstance final {
bool has_buffer() const { return m_buffer != nullptr; }
void buffer_add_pc(u64 pc);

Spinlock<u8> lock;
Spinlock lock;
enum {
UNUSED = 0,
OPENED = 1,
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/SerialDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class SerialDevice final : public CharacterDevice {
bool m_break_enable { false };
u8 m_modem_control { 0 };
bool m_last_put_char_was_carriage_return { false };
Spinlock<u8> m_serial_lock;
Spinlock m_serial_lock;
};

}
6 changes: 3 additions & 3 deletions Kernel/FileSystem/Plan9FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class Plan9FS final : public FileBackedFileSystem {

private:
Plan9FS& m_fs;
mutable Spinlock<u8> m_lock;
mutable Spinlock m_lock;
};

struct ReceiveCompletion : public RefCounted<ReceiveCompletion> {
mutable Spinlock<u8> lock;
mutable Spinlock lock;
bool completed { false };
const u16 tag;
OwnPtr<Message> message;
Expand Down Expand Up @@ -139,7 +139,7 @@ class Plan9FS final : public FileBackedFileSystem {
Plan9FSBlockerSet m_completion_blocker;
HashMap<u16, NonnullRefPtr<ReceiveCompletion>> m_completions;

Spinlock<u8> m_thread_lock;
Spinlock m_thread_lock;
RefPtr<Thread> m_thread;
Atomic<bool> m_thread_running { false };
Atomic<bool, AK::MemoryOrder::memory_order_relaxed> m_thread_shutdown { false };
Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/SysFSComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Kernel {

static Spinlock<u8> s_index_lock;
static Spinlock s_index_lock;
static InodeIndex s_next_inode_index { 0 };

static size_t allocate_inode_index()
Expand Down
1 change: 0 additions & 1 deletion Kernel/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class VirtualRange;
class VirtualRangeAllocator;
}

template<typename BaseType>
class Spinlock;
template<typename LockType>
class SpinlockLocker;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Graphics/Bochs/GraphicsAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class BochsGraphicsAdapter final : public GraphicsDevice
Memory::TypedMapping<BochsDisplayMMIORegisters volatile> m_registers;
RefPtr<FramebufferDevice> m_framebuffer_device;
RefPtr<Graphics::GenericFramebufferConsole> m_framebuffer_console;
Spinlock<u8> m_console_mode_switch_lock;
Spinlock m_console_mode_switch_lock;
bool m_console_enabled { false };
bool m_io_required { false };
};
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Graphics/Console/GenericFramebufferConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ class GenericFramebufferConsole : public Console {
virtual u8* framebuffer_data() = 0;
void clear_glyph(size_t x, size_t y);
size_t m_pitch;
mutable Spinlock<u8> m_lock;
mutable Spinlock m_lock;
};
}
2 changes: 1 addition & 1 deletion Kernel/Graphics/Console/TextModeConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TextModeConsole final : public VGAConsole {

explicit TextModeConsole(const VGACompatibleAdapter&);

mutable Spinlock<u8> m_vga_lock;
mutable Spinlock m_vga_lock;
u16 m_vga_start_row { 0 };
u16 m_current_vga_start_address { 0 };
u8* m_current_vga_window { nullptr };
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Graphics/FramebufferDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FramebufferDevice : public BlockDevice {
size_t m_framebuffer_width { 0 };
size_t m_framebuffer_height { 0 };

Spinlock<u8> m_activation_lock;
Spinlock m_activation_lock;

RefPtr<Memory::AnonymousVMObject> m_real_framebuffer_vmobject;
RefPtr<Memory::AnonymousVMObject> m_swapped_framebuffer_vmobject;
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Graphics/GraphicsManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GraphicsManagement {
bool framebuffer_devices_allowed() const { return m_framebuffer_devices_allowed; }
bool framebuffer_devices_exist() const;

Spinlock<u8>& main_vga_lock() { return m_main_vga_lock; }
Spinlock& main_vga_lock() { return m_main_vga_lock; }
RefPtr<Graphics::Console> console() const { return m_console; }

void deactivate_graphical_mode();
Expand All @@ -56,7 +56,7 @@ class GraphicsManagement {
unsigned m_current_minor_number { 0 };
const bool m_framebuffer_devices_allowed;

Spinlock<u8> m_main_vga_lock;
Spinlock m_main_vga_lock;
};

}
6 changes: 3 additions & 3 deletions Kernel/Graphics/Intel/NativeGraphicsAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ class IntelNativeGraphicsAdapter final

Optional<PLLSettings> create_pll_settings(u64 target_frequency, u64 reference_clock, const PLLMaxSettings&);

Spinlock<u8> m_control_lock;
Spinlock<u8> m_modeset_lock;
mutable Spinlock<u8> m_registers_lock;
Spinlock m_control_lock;
Spinlock m_modeset_lock;
mutable Spinlock m_registers_lock;

Graphics::VideoInfoBlock m_crt_edid;
const PhysicalAddress m_registers;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Locking/Mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void Mutex::unlock()
}
}

void Mutex::block(Thread& current_thread, Mode mode, SpinlockLocker<Spinlock<u8>>& lock, u32 requested_locks)
void Mutex::block(Thread& current_thread, Mode mode, SpinlockLocker<Spinlock>& lock, u32 requested_locks)
{
if constexpr (LOCK_IN_CRITICAL_DEBUG)
VERIFY_INTERRUPTS_ENABLED();
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Locking/Mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Mutex {
return mode == Mode::Exclusive ? m_blocked_threads_list_exclusive : m_blocked_threads_list_shared;
}

void block(Thread&, Mode, SpinlockLocker<Spinlock<u8>>&, u32);
void block(Thread&, Mode, SpinlockLocker<Spinlock>&, u32);
void unblock_waiters(Mode);

StringView m_name;
Expand All @@ -98,7 +98,7 @@ class Mutex {
BlockedThreadList m_blocked_threads_list_exclusive;
BlockedThreadList m_blocked_threads_list_shared;

mutable Spinlock<u8> m_lock;
mutable Spinlock m_lock;
};

class MutexLocker {
Expand Down
3 changes: 1 addition & 2 deletions Kernel/Locking/Spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Kernel {

template<typename BaseType = u32>
class Spinlock {
AK_MAKE_NONCOPYABLE(Spinlock);
AK_MAKE_NONMOVABLE(Spinlock);
Expand Down Expand Up @@ -54,7 +53,7 @@ class Spinlock {
}

private:
Atomic<BaseType> m_lock { 0 };
Atomic<u8> m_lock { 0 };
};

class RecursiveSpinlock {
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Memory/AnonymousVMObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class AnonymousVMObject final : public VMObject {
void uncommit_one();

public:
Spinlock<u8> m_lock;
Spinlock m_lock;
CommittedPhysicalPageSet m_committed_pages;
};

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Memory/MemoryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct PhysicalMemoryRange {
struct MemoryManagerData {
static ProcessorSpecificDataID processor_specific_data_id() { return ProcessorSpecificDataID::MemoryManager; }

Spinlock<u8> m_quickmap_in_use;
Spinlock m_quickmap_in_use;
u32 m_quickmap_prev_flags;

PhysicalAddress m_last_quickmap_pd;
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Memory/RingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class RingBuffer {
void reclaim_space(PhysicalAddress chunk_start, size_t chunk_size);
PhysicalAddress start_of_used() const;

Spinlock<u8>& lock() { return m_lock; }
Spinlock& lock() { return m_lock; }
size_t used_bytes() const { return m_num_used_bytes; }
PhysicalAddress start_of_region() const { return m_region->physical_page(0)->paddr(); }
VirtualAddress vaddr() const { return m_region->vaddr(); }
size_t bytes_till_end() const { return (m_capacity_in_bytes - ((m_start_of_used + m_num_used_bytes) % m_capacity_in_bytes)) % m_capacity_in_bytes; };

private:
OwnPtr<Memory::Region> m_region;
Spinlock<u8> m_lock;
Spinlock m_lock;
size_t m_start_of_used {};
size_t m_num_used_bytes {};
size_t m_capacity_in_bytes {};
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Memory/VirtualRangeAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class VirtualRangeAllocator {

RedBlackTree<FlatPtr, VirtualRange> m_available_ranges;
VirtualRange m_total_range;
mutable Spinlock<u8> m_lock;
mutable Spinlock m_lock;
};

}
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ class Process final
private:
FileDescriptions() = default;
static constexpr size_t m_max_open_file_descriptors { FD_SETSIZE };
mutable Spinlock<u8> m_fds_lock;
mutable Spinlock m_fds_lock;
Vector<FileDescriptionAndFlags> m_fds_metadatas;
};

Expand Down Expand Up @@ -782,7 +782,7 @@ class Process final
OwnPtr<PerformanceEventBuffer> m_perf_event_buffer;

FutexQueues m_futex_queues;
Spinlock<u8> m_futex_lock;
Spinlock m_futex_lock;

// This member is used in the implementation of ptrace's PT_TRACEME flag.
// If it is set to true, the process will stop at the next execve syscall
Expand Down
2 changes: 1 addition & 1 deletion Kernel/ProcessExposed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Kernel {

static Spinlock<u8> s_index_lock;
static Spinlock s_index_lock;
static InodeIndex s_next_inode_index = 0;

namespace SegmentedProcFSIndex {
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class FortunaPRNG {
return is_seeded() || m_p0_len >= reseed_threshold;
}

Spinlock<u8>& get_lock() { return m_lock; }
Spinlock& get_lock() { return m_lock; }

private:
void reseed()
Expand All @@ -107,7 +107,7 @@ class FortunaPRNG {
size_t m_p0_len { 0 };
ByteBuffer m_key;
HashType m_pools[pool_count];
Spinlock<u8> m_lock;
Spinlock m_lock;
};

class KernelRng : public Lockable<FortunaPRNG<Crypto::Cipher::AESCipher, Crypto::Hash::SHA256, 256>> {
Expand All @@ -121,7 +121,7 @@ class KernelRng : public Lockable<FortunaPRNG<Crypto::Cipher::AESCipher, Crypto:

void wake_if_ready();

Spinlock<u8>& get_lock() { return resource().get_lock(); }
Spinlock& get_lock() { return resource().get_lock(); }

private:
WaitQueue m_seed_queue;
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Storage/AHCIPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ bool AHCIPort::initialize_without_reset()
return initialize(lock);
}

bool AHCIPort::initialize(SpinlockLocker<Spinlock<u8>>& main_lock)
bool AHCIPort::initialize(SpinlockLocker<Spinlock>& main_lock)
{
VERIFY(m_lock.is_locked());
dbgln_if(AHCI_DEBUG, "AHCI Port {}: Initialization. Signature = {:#08x}", representative_port_index(), static_cast<u32>(m_port_registers.sig));
Expand Down Expand Up @@ -591,7 +591,7 @@ bool AHCIPort::access_device(AsyncBlockDeviceRequest::RequestType direction, u64
return true;
}

bool AHCIPort::identify_device(SpinlockLocker<Spinlock<u8>>& main_lock)
bool AHCIPort::identify_device(SpinlockLocker<Spinlock>& main_lock)
{
VERIFY(m_lock.is_locked());
VERIFY(is_operable());
Expand Down Expand Up @@ -740,7 +740,7 @@ void AHCIPort::stop_fis_receiving() const
m_port_registers.cmd = m_port_registers.cmd & 0xFFFFFFEF;
}

bool AHCIPort::initiate_sata_reset(SpinlockLocker<Spinlock<u8>>& main_lock)
bool AHCIPort::initiate_sata_reset(SpinlockLocker<Spinlock>& main_lock)
{
VERIFY(m_lock.is_locked());
VERIFY(m_hard_lock.is_locked());
Expand Down
Loading

0 comments on commit bb58a4d

Please sign in to comment.