Skip to content

Commit bb58a4d

Browse files
bgianfoawesomekling
authored andcommitted
Kernel: Make all Spinlocks use u8 for storage, remove template
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.
1 parent 5905d2e commit bb58a4d

38 files changed

+56
-58
lines changed

Documentation/Kernel/AHCILocking.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ return true;
1818
1919
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.
2020
21-
### Hard lock - `SpinLock<u8>`
21+
### Hard lock - `Spinlock`
2222
2323
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:
2424

Kernel/Bus/PCI/MMIOAccess.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MMIOAccess : public Access {
4444
PhysicalAddress determine_memory_mapped_bus_region(u32 segment, u8 bus) const;
4545
void map_bus_region(u32, u8);
4646
VirtualAddress get_device_configuration_space(Address address);
47-
Spinlock<u8> m_access_lock;
47+
Spinlock m_access_lock;
4848
u8 m_mapped_bus { 0 };
4949
OwnPtr<Memory::Region> m_mapped_region;
5050

Kernel/Bus/USB/SysFSUSB.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class SysFSUSBBusDirectory final : public SysFSDirectory {
5555
RefPtr<SysFSUSBDeviceInformation> device_node_for(USB::Device& device);
5656

5757
IntrusiveList<SysFSUSBDeviceInformation, RefPtr<SysFSUSBDeviceInformation>, &SysFSUSBDeviceInformation::m_list_node> m_device_nodes;
58-
mutable Spinlock<u8> m_lock;
58+
mutable Spinlock m_lock;
5959
};
6060

6161
}

Kernel/Bus/VirtIO/Queue.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Queue {
4747
QueueChain pop_used_buffer_chain(size_t& used);
4848
void discard_used_buffers();
4949

50-
Spinlock<u8>& lock() { return m_lock; }
50+
Spinlock& lock() { return m_lock; }
5151

5252
bool should_notify() const;
5353

@@ -94,7 +94,7 @@ class Queue {
9494
OwnPtr<QueueDriver> m_driver { nullptr };
9595
OwnPtr<QueueDevice> m_device { nullptr };
9696
OwnPtr<Memory::Region> m_queue_region;
97-
Spinlock<u8> m_lock;
97+
Spinlock m_lock;
9898

9999
friend class QueueChain;
100100
};

Kernel/Devices/AsyncDeviceRequest.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class AsyncDeviceRequest : public RefCounted<AsyncDeviceRequest> {
6161

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

64-
void do_start(SpinlockLocker<Spinlock<u8>>&& requests_lock)
64+
void do_start(SpinlockLocker<Spinlock>&& requests_lock)
6565
{
6666
if (is_completed_result(m_result))
6767
return;
@@ -150,7 +150,7 @@ class AsyncDeviceRequest : public RefCounted<AsyncDeviceRequest> {
150150
WaitQueue m_queue;
151151
NonnullRefPtr<Process> m_process;
152152
void* m_private { nullptr };
153-
mutable Spinlock<u8> m_lock;
153+
mutable Spinlock m_lock;
154154
};
155155

156156
}

Kernel/Devices/Device.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Device : public File {
7272
UserID m_uid { 0 };
7373
GroupID m_gid { 0 };
7474

75-
Spinlock<u8> m_requests_lock;
75+
Spinlock m_requests_lock;
7676
DoublyLinkedList<RefPtr<AsyncDeviceRequest>> m_requests;
7777
};
7878

Kernel/Devices/HID/I8042Controller.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class I8042Controller : public RefCounted<I8042Controller> {
105105
void do_wait_then_write(u8 port, u8 data);
106106
u8 do_wait_then_read(u8 port);
107107

108-
Spinlock<u8> m_lock;
108+
Spinlock m_lock;
109109
bool m_first_port_available { false };
110110
bool m_second_port_available { false };
111111
bool m_is_dual_channel { false };

Kernel/Devices/HID/KeyboardDevice.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class KeyboardDevice : public HIDDevice {
5151

5252
protected:
5353
KeyboardDevice();
54-
mutable Spinlock<u8> m_queue_lock;
54+
mutable Spinlock m_queue_lock;
5555
CircularQueue<Event, 16> m_queue;
5656
// ^CharacterDevice
5757
virtual StringView class_name() const override { return "KeyboardDevice"; }

Kernel/Devices/HID/MouseDevice.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MouseDevice : public HIDDevice {
4141
// ^CharacterDevice
4242
virtual StringView class_name() const override { return "MouseDevice"; }
4343

44-
mutable Spinlock<u8> m_queue_lock;
44+
mutable Spinlock m_queue_lock;
4545
CircularQueue<MousePacket, 100> m_queue;
4646
};
4747

Kernel/Devices/KCOVInstance.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class KCOVInstance final {
3535
bool has_buffer() const { return m_buffer != nullptr; }
3636
void buffer_add_pc(u64 pc);
3737

38-
Spinlock<u8> lock;
38+
Spinlock lock;
3939
enum {
4040
UNUSED = 0,
4141
OPENED = 1,

Kernel/Devices/SerialDevice.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class SerialDevice final : public CharacterDevice {
133133
bool m_break_enable { false };
134134
u8 m_modem_control { 0 };
135135
bool m_last_put_char_was_carriage_return { false };
136-
Spinlock<u8> m_serial_lock;
136+
Spinlock m_serial_lock;
137137
};
138138

139139
}

Kernel/FileSystem/Plan9FileSystem.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ class Plan9FS final : public FileBackedFileSystem {
6666

6767
private:
6868
Plan9FS& m_fs;
69-
mutable Spinlock<u8> m_lock;
69+
mutable Spinlock m_lock;
7070
};
7171

7272
struct ReceiveCompletion : public RefCounted<ReceiveCompletion> {
73-
mutable Spinlock<u8> lock;
73+
mutable Spinlock lock;
7474
bool completed { false };
7575
const u16 tag;
7676
OwnPtr<Message> message;
@@ -139,7 +139,7 @@ class Plan9FS final : public FileBackedFileSystem {
139139
Plan9FSBlockerSet m_completion_blocker;
140140
HashMap<u16, NonnullRefPtr<ReceiveCompletion>> m_completions;
141141

142-
Spinlock<u8> m_thread_lock;
142+
Spinlock m_thread_lock;
143143
RefPtr<Thread> m_thread;
144144
Atomic<bool> m_thread_running { false };
145145
Atomic<bool, AK::MemoryOrder::memory_order_relaxed> m_thread_shutdown { false };

Kernel/FileSystem/SysFSComponent.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Kernel {
1111

12-
static Spinlock<u8> s_index_lock;
12+
static Spinlock s_index_lock;
1313
static InodeIndex s_next_inode_index { 0 };
1414

1515
static size_t allocate_inode_index()

Kernel/Forward.h

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class VirtualRange;
8484
class VirtualRangeAllocator;
8585
}
8686

87-
template<typename BaseType>
8887
class Spinlock;
8988
template<typename LockType>
9089
class SpinlockLocker;

Kernel/Graphics/Bochs/GraphicsAdapter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class BochsGraphicsAdapter final : public GraphicsDevice
6060
Memory::TypedMapping<BochsDisplayMMIORegisters volatile> m_registers;
6161
RefPtr<FramebufferDevice> m_framebuffer_device;
6262
RefPtr<Graphics::GenericFramebufferConsole> m_framebuffer_console;
63-
Spinlock<u8> m_console_mode_switch_lock;
63+
Spinlock m_console_mode_switch_lock;
6464
bool m_console_enabled { false };
6565
bool m_io_required { false };
6666
};

Kernel/Graphics/Console/GenericFramebufferConsole.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ class GenericFramebufferConsole : public Console {
4747
virtual u8* framebuffer_data() = 0;
4848
void clear_glyph(size_t x, size_t y);
4949
size_t m_pitch;
50-
mutable Spinlock<u8> m_lock;
50+
mutable Spinlock m_lock;
5151
};
5252
}

Kernel/Graphics/Console/TextModeConsole.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TextModeConsole final : public VGAConsole {
3939

4040
explicit TextModeConsole(const VGACompatibleAdapter&);
4141

42-
mutable Spinlock<u8> m_vga_lock;
42+
mutable Spinlock m_vga_lock;
4343
u16 m_vga_start_row { 0 };
4444
u16 m_current_vga_start_address { 0 };
4545
u8* m_current_vga_window { nullptr };

Kernel/Graphics/FramebufferDevice.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class FramebufferDevice : public BlockDevice {
5353
size_t m_framebuffer_width { 0 };
5454
size_t m_framebuffer_height { 0 };
5555

56-
Spinlock<u8> m_activation_lock;
56+
Spinlock m_activation_lock;
5757

5858
RefPtr<Memory::AnonymousVMObject> m_real_framebuffer_vmobject;
5959
RefPtr<Memory::AnonymousVMObject> m_swapped_framebuffer_vmobject;

Kernel/Graphics/GraphicsManagement.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class GraphicsManagement {
4040
bool framebuffer_devices_allowed() const { return m_framebuffer_devices_allowed; }
4141
bool framebuffer_devices_exist() const;
4242

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

4646
void deactivate_graphical_mode();
@@ -56,7 +56,7 @@ class GraphicsManagement {
5656
unsigned m_current_minor_number { 0 };
5757
const bool m_framebuffer_devices_allowed;
5858

59-
Spinlock<u8> m_main_vga_lock;
59+
Spinlock m_main_vga_lock;
6060
};
6161

6262
}

Kernel/Graphics/Intel/NativeGraphicsAdapter.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ class IntelNativeGraphicsAdapter final
161161

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

164-
Spinlock<u8> m_control_lock;
165-
Spinlock<u8> m_modeset_lock;
166-
mutable Spinlock<u8> m_registers_lock;
164+
Spinlock m_control_lock;
165+
Spinlock m_modeset_lock;
166+
mutable Spinlock m_registers_lock;
167167

168168
Graphics::VideoInfoBlock m_crt_edid;
169169
const PhysicalAddress m_registers;

Kernel/Locking/Mutex.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void Mutex::unlock()
200200
}
201201
}
202202

203-
void Mutex::block(Thread& current_thread, Mode mode, SpinlockLocker<Spinlock<u8>>& lock, u32 requested_locks)
203+
void Mutex::block(Thread& current_thread, Mode mode, SpinlockLocker<Spinlock>& lock, u32 requested_locks)
204204
{
205205
if constexpr (LOCK_IN_CRITICAL_DEBUG)
206206
VERIFY_INTERRUPTS_ENABLED();

Kernel/Locking/Mutex.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Mutex {
7777
return mode == Mode::Exclusive ? m_blocked_threads_list_exclusive : m_blocked_threads_list_shared;
7878
}
7979

80-
void block(Thread&, Mode, SpinlockLocker<Spinlock<u8>>&, u32);
80+
void block(Thread&, Mode, SpinlockLocker<Spinlock>&, u32);
8181
void unblock_waiters(Mode);
8282

8383
StringView m_name;
@@ -98,7 +98,7 @@ class Mutex {
9898
BlockedThreadList m_blocked_threads_list_exclusive;
9999
BlockedThreadList m_blocked_threads_list_shared;
100100

101-
mutable Spinlock<u8> m_lock;
101+
mutable Spinlock m_lock;
102102
};
103103

104104
class MutexLocker {

Kernel/Locking/Spinlock.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Kernel {
1515

16-
template<typename BaseType = u32>
1716
class Spinlock {
1817
AK_MAKE_NONCOPYABLE(Spinlock);
1918
AK_MAKE_NONMOVABLE(Spinlock);
@@ -54,7 +53,7 @@ class Spinlock {
5453
}
5554

5655
private:
57-
Atomic<BaseType> m_lock { 0 };
56+
Atomic<u8> m_lock { 0 };
5857
};
5958

6059
class RecursiveSpinlock {

Kernel/Memory/AnonymousVMObject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class AnonymousVMObject final : public VMObject {
7676
void uncommit_one();
7777

7878
public:
79-
Spinlock<u8> m_lock;
79+
Spinlock m_lock;
8080
CommittedPhysicalPageSet m_committed_pages;
8181
};
8282

Kernel/Memory/MemoryManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct PhysicalMemoryRange {
9393
struct MemoryManagerData {
9494
static ProcessorSpecificDataID processor_specific_data_id() { return ProcessorSpecificDataID::MemoryManager; }
9595

96-
Spinlock<u8> m_quickmap_in_use;
96+
Spinlock m_quickmap_in_use;
9797
u32 m_quickmap_prev_flags;
9898

9999
PhysicalAddress m_last_quickmap_pd;

Kernel/Memory/RingBuffer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class RingBuffer {
2323
void reclaim_space(PhysicalAddress chunk_start, size_t chunk_size);
2424
PhysicalAddress start_of_used() const;
2525

26-
Spinlock<u8>& lock() { return m_lock; }
26+
Spinlock& lock() { return m_lock; }
2727
size_t used_bytes() const { return m_num_used_bytes; }
2828
PhysicalAddress start_of_region() const { return m_region->physical_page(0)->paddr(); }
2929
VirtualAddress vaddr() const { return m_region->vaddr(); }
3030
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; };
3131

3232
private:
3333
OwnPtr<Memory::Region> m_region;
34-
Spinlock<u8> m_lock;
34+
Spinlock m_lock;
3535
size_t m_start_of_used {};
3636
size_t m_num_used_bytes {};
3737
size_t m_capacity_in_bytes {};

Kernel/Memory/VirtualRangeAllocator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class VirtualRangeAllocator {
3535

3636
RedBlackTree<FlatPtr, VirtualRange> m_available_ranges;
3737
VirtualRange m_total_range;
38-
mutable Spinlock<u8> m_lock;
38+
mutable Spinlock m_lock;
3939
};
4040

4141
}

Kernel/Process.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ class Process final
681681
private:
682682
FileDescriptions() = default;
683683
static constexpr size_t m_max_open_file_descriptors { FD_SETSIZE };
684-
mutable Spinlock<u8> m_fds_lock;
684+
mutable Spinlock m_fds_lock;
685685
Vector<FileDescriptionAndFlags> m_fds_metadatas;
686686
};
687687

@@ -782,7 +782,7 @@ class Process final
782782
OwnPtr<PerformanceEventBuffer> m_perf_event_buffer;
783783

784784
FutexQueues m_futex_queues;
785-
Spinlock<u8> m_futex_lock;
785+
Spinlock m_futex_lock;
786786

787787
// This member is used in the implementation of ptrace's PT_TRACEME flag.
788788
// If it is set to true, the process will stop at the next execve syscall

Kernel/ProcessExposed.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Kernel {
1717

18-
static Spinlock<u8> s_index_lock;
18+
static Spinlock s_index_lock;
1919
static InodeIndex s_next_inode_index = 0;
2020

2121
namespace SegmentedProcFSIndex {

Kernel/Random.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class FortunaPRNG {
8181
return is_seeded() || m_p0_len >= reseed_threshold;
8282
}
8383

84-
Spinlock<u8>& get_lock() { return m_lock; }
84+
Spinlock& get_lock() { return m_lock; }
8585

8686
private:
8787
void reseed()
@@ -107,7 +107,7 @@ class FortunaPRNG {
107107
size_t m_p0_len { 0 };
108108
ByteBuffer m_key;
109109
HashType m_pools[pool_count];
110-
Spinlock<u8> m_lock;
110+
Spinlock m_lock;
111111
};
112112

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

122122
void wake_if_ready();
123123

124-
Spinlock<u8>& get_lock() { return resource().get_lock(); }
124+
Spinlock& get_lock() { return resource().get_lock(); }
125125

126126
private:
127127
WaitQueue m_seed_queue;

Kernel/Storage/AHCIPort.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ bool AHCIPort::initialize_without_reset()
238238
return initialize(lock);
239239
}
240240

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

594-
bool AHCIPort::identify_device(SpinlockLocker<Spinlock<u8>>& main_lock)
594+
bool AHCIPort::identify_device(SpinlockLocker<Spinlock>& main_lock)
595595
{
596596
VERIFY(m_lock.is_locked());
597597
VERIFY(is_operable());
@@ -740,7 +740,7 @@ void AHCIPort::stop_fis_receiving() const
740740
m_port_registers.cmd = m_port_registers.cmd & 0xFFFFFFEF;
741741
}
742742

743-
bool AHCIPort::initiate_sata_reset(SpinlockLocker<Spinlock<u8>>& main_lock)
743+
bool AHCIPort::initiate_sata_reset(SpinlockLocker<Spinlock>& main_lock)
744744
{
745745
VERIFY(m_lock.is_locked());
746746
VERIFY(m_hard_lock.is_locked());

0 commit comments

Comments
 (0)