Skip to content

Commit

Permalink
Kernel: Rename ScopedSpinlock => SpinlockLocker
Browse files Browse the repository at this point in the history
This matches MutexLocker, and doesn't sound like it's a lock itself.
  • Loading branch information
awesomekling committed Aug 22, 2021
1 parent 55adace commit c922a7d
Show file tree
Hide file tree
Showing 78 changed files with 365 additions and 366 deletions.
2 changes: 1 addition & 1 deletion Kernel/Arch/x86/common/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ Vector<FlatPtr> Processor::capture_stack_trace(Thread& thread, size_t max_frames
// is a chance a context switch may happen while we're trying
// to get it. It also won't be entirely accurate and merely
// reflect the status at the last context switch.
ScopedSpinlock lock(g_scheduler_lock);
SpinlockLocker lock(g_scheduler_lock);
if (&thread == Processor::current_thread()) {
VERIFY(thread.state() == Thread::Running);
// Leave the scheduler lock. If we trigger page faults we may
Expand Down
12 changes: 6 additions & 6 deletions Kernel/Bus/PCI/MMIOAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ VirtualAddress MMIOAccess::get_device_configuration_space(Address address)

u8 MMIOAccess::read8_field(Address address, u32 field)
{
ScopedSpinlock lock(m_access_lock);
SpinlockLocker lock(m_access_lock);
VERIFY(field <= 0xfff);
dbgln_if(PCI_DEBUG, "PCI: MMIO Reading 8-bit field {:#08x} for {}", field, address);
return *((volatile u8*)(get_device_configuration_space(address).get() + (field & 0xfff)));
}

u16 MMIOAccess::read16_field(Address address, u32 field)
{
ScopedSpinlock lock(m_access_lock);
SpinlockLocker lock(m_access_lock);
VERIFY(field < 0xfff);
dbgln_if(PCI_DEBUG, "PCI: MMIO Reading 16-bit field {:#08x} for {}", field, address);
u16 data = 0;
Expand All @@ -135,7 +135,7 @@ u16 MMIOAccess::read16_field(Address address, u32 field)

u32 MMIOAccess::read32_field(Address address, u32 field)
{
ScopedSpinlock lock(m_access_lock);
SpinlockLocker lock(m_access_lock);
VERIFY(field <= 0xffc);
dbgln_if(PCI_DEBUG, "PCI: MMIO Reading 32-bit field {:#08x} for {}", field, address);
u32 data = 0;
Expand All @@ -145,21 +145,21 @@ u32 MMIOAccess::read32_field(Address address, u32 field)

void MMIOAccess::write8_field(Address address, u32 field, u8 value)
{
ScopedSpinlock lock(m_access_lock);
SpinlockLocker lock(m_access_lock);
VERIFY(field <= 0xfff);
dbgln_if(PCI_DEBUG, "PCI: MMIO Writing 8-bit field {:#08x}, value={:#02x} for {}", field, value, address);
*((volatile u8*)(get_device_configuration_space(address).get() + (field & 0xfff))) = value;
}
void MMIOAccess::write16_field(Address address, u32 field, u16 value)
{
ScopedSpinlock lock(m_access_lock);
SpinlockLocker lock(m_access_lock);
VERIFY(field < 0xfff);
dbgln_if(PCI_DEBUG, "PCI: MMIO Writing 16-bit field {:#08x}, value={:#02x} for {}", field, value, address);
ByteReader::store<u16>(get_device_configuration_space(address).offset(field & 0xfff).as_ptr(), value);
}
void MMIOAccess::write32_field(Address address, u32 field, u32 value)
{
ScopedSpinlock lock(m_access_lock);
SpinlockLocker lock(m_access_lock);
VERIFY(field <= 0xffc);
dbgln_if(PCI_DEBUG, "PCI: MMIO Writing 32-bit field {:#08x}, value={:#02x} for {}", field, value, address);
ByteReader::store<u32>(get_device_configuration_space(address).offset(field & 0xfff).as_ptr(), value);
Expand Down
8 changes: 4 additions & 4 deletions Kernel/Bus/USB/SysFSUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ KResultOr<size_t> SysFSUSBDeviceInformation::read_bytes(off_t offset, size_t cou

KResult SysFSUSBBusDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
// Note: if the parent directory is null, it means something bad happened as this should not happen for the USB directory.
VERIFY(m_parent_directory);
callback({ ".", { fsid, component_index() }, 0 });
Expand All @@ -72,7 +72,7 @@ KResult SysFSUSBBusDirectory::traverse_as_directory(unsigned fsid, Function<bool

RefPtr<SysFSComponent> SysFSUSBBusDirectory::lookup(StringView name)
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
for (auto& device_node : m_device_nodes) {
if (device_node.name() == name) {
return device_node;
Expand All @@ -93,15 +93,15 @@ RefPtr<SysFSUSBDeviceInformation> SysFSUSBBusDirectory::device_node_for(USB::Dev

void SysFSUSBBusDirectory::plug(USB::Device& new_device)
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
auto device_node = device_node_for(new_device);
VERIFY(!device_node);
m_device_nodes.append(SysFSUSBDeviceInformation::create(new_device));
}

void SysFSUSBBusDirectory::unplug(USB::Device& deleted_device)
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
auto device_node = device_node_for(deleted_device);
VERIFY(device_node);
device_node->m_list_node.remove();
Expand Down
14 changes: 7 additions & 7 deletions Kernel/Bus/VirtIO/VirtIOConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ void VirtIOConsole::handle_queue_update(u16 queue_index)
dbgln_if(VIRTIO_DEBUG, "VirtIOConsole: Handle queue update {}", queue_index);

if (queue_index == CONTROL_RECEIVEQ) {
ScopedSpinlock ringbuffer_lock(m_control_receive_buffer->lock());
SpinlockLocker ringbuffer_lock(m_control_receive_buffer->lock());
auto& queue = get_queue(CONTROL_RECEIVEQ);
ScopedSpinlock queue_lock(queue.lock());
SpinlockLocker queue_lock(queue.lock());
size_t used;
VirtIOQueueChain popped_chain = queue.pop_used_buffer_chain(used);

Expand All @@ -81,9 +81,9 @@ void VirtIOConsole::handle_queue_update(u16 queue_index)
popped_chain = queue.pop_used_buffer_chain(used);
}
} else if (queue_index == CONTROL_TRANSMITQ) {
ScopedSpinlock ringbuffer_lock(m_control_transmit_buffer->lock());
SpinlockLocker ringbuffer_lock(m_control_transmit_buffer->lock());
auto& queue = get_queue(CONTROL_TRANSMITQ);
ScopedSpinlock queue_lock(queue.lock());
SpinlockLocker queue_lock(queue.lock());
size_t used;
VirtIOQueueChain popped_chain = queue.pop_used_buffer_chain(used);
auto number_of_messages = 0;
Expand Down Expand Up @@ -112,7 +112,7 @@ void VirtIOConsole::setup_multiport()
m_control_transmit_buffer = make<Memory::RingBuffer>("VirtIOConsole control transmit queue", CONTROL_BUFFER_SIZE);

auto& queue = get_queue(CONTROL_RECEIVEQ);
ScopedSpinlock queue_lock(queue.lock());
SpinlockLocker queue_lock(queue.lock());
VirtIOQueueChain chain(queue);
auto offset = 0ul;

Expand Down Expand Up @@ -184,7 +184,7 @@ void VirtIOConsole::process_control_message(ControlMessage message)
}
void VirtIOConsole::write_control_message(ControlMessage message)
{
ScopedSpinlock ringbuffer_lock(m_control_transmit_buffer->lock());
SpinlockLocker ringbuffer_lock(m_control_transmit_buffer->lock());

PhysicalAddress start_of_chunk;
size_t length_of_chunk;
Expand All @@ -197,7 +197,7 @@ void VirtIOConsole::write_control_message(ControlMessage message)
}

auto& queue = get_queue(CONTROL_TRANSMITQ);
ScopedSpinlock queue_lock(queue.lock());
SpinlockLocker queue_lock(queue.lock());
VirtIOQueueChain chain(queue);

bool did_add_buffer = chain.add_buffer_to_chain(start_of_chunk, length_of_chunk, BufferType::DeviceReadable);
Expand Down
18 changes: 9 additions & 9 deletions Kernel/Bus/VirtIO/VirtIOConsolePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ VirtIOConsolePort::VirtIOConsolePort(unsigned port, VirtIOConsole& console)
void VirtIOConsolePort::init_receive_buffer()
{
auto& queue = m_console.get_queue(m_receive_queue);
ScopedSpinlock queue_lock(queue.lock());
SpinlockLocker queue_lock(queue.lock());
VirtIOQueueChain chain(queue);

auto buffer_start = m_receive_buffer->start_of_region();
Expand All @@ -42,11 +42,11 @@ void VirtIOConsolePort::handle_queue_update(Badge<VirtIOConsole>, u16 queue_inde
VERIFY(queue_index == m_transmit_queue || queue_index == m_receive_queue);
if (queue_index == m_receive_queue) {
auto& queue = m_console.get_queue(m_receive_queue);
ScopedSpinlock queue_lock(queue.lock());
SpinlockLocker queue_lock(queue.lock());
size_t used;
VirtIOQueueChain popped_chain = queue.pop_used_buffer_chain(used);

ScopedSpinlock ringbuffer_lock(m_receive_buffer->lock());
SpinlockLocker ringbuffer_lock(m_receive_buffer->lock());
auto used_space = m_receive_buffer->reserve_space(used).value();
auto remaining_space = m_receive_buffer->bytes_till_end();

Expand All @@ -65,9 +65,9 @@ void VirtIOConsolePort::handle_queue_update(Badge<VirtIOConsole>, u16 queue_inde

evaluate_block_conditions();
} else {
ScopedSpinlock ringbuffer_lock(m_transmit_buffer->lock());
SpinlockLocker ringbuffer_lock(m_transmit_buffer->lock());
auto& queue = m_console.get_queue(m_transmit_queue);
ScopedSpinlock queue_lock(queue.lock());
SpinlockLocker queue_lock(queue.lock());
size_t used;
VirtIOQueueChain popped_chain = queue.pop_used_buffer_chain(used);
do {
Expand All @@ -92,7 +92,7 @@ KResultOr<size_t> VirtIOConsolePort::read(FileDescription& desc, u64, UserOrKern
if (!size)
return 0;

ScopedSpinlock ringbuffer_lock(m_receive_buffer->lock());
SpinlockLocker ringbuffer_lock(m_receive_buffer->lock());

if (!can_read(desc, size))
return EAGAIN;
Expand All @@ -102,7 +102,7 @@ KResultOr<size_t> VirtIOConsolePort::read(FileDescription& desc, u64, UserOrKern

if (m_receive_buffer_exhausted && m_receive_buffer->used_bytes() == 0) {
auto& queue = m_console.get_queue(m_receive_queue);
ScopedSpinlock queue_lock(queue.lock());
SpinlockLocker queue_lock(queue.lock());
VirtIOQueueChain new_chain(queue);
new_chain.add_buffer_to_chain(m_receive_buffer->start_of_region(), RINGBUFFER_SIZE, BufferType::DeviceWritable);
m_console.supply_chain_and_notify(m_receive_queue, new_chain);
Expand All @@ -122,9 +122,9 @@ KResultOr<size_t> VirtIOConsolePort::write(FileDescription& desc, u64, const Use
if (!size)
return 0;

ScopedSpinlock ringbuffer_lock(m_transmit_buffer->lock());
SpinlockLocker ringbuffer_lock(m_transmit_buffer->lock());
auto& queue = m_console.get_queue(m_transmit_queue);
ScopedSpinlock queue_lock(queue.lock());
SpinlockLocker queue_lock(queue.lock());

if (!can_write(desc, size))
return EAGAIN;
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Bus/VirtIO/VirtIOQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ VirtIOQueue::~VirtIOQueue()

void VirtIOQueue::enable_interrupts()
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
m_driver->flags = 0;
}

void VirtIOQueue::disable_interrupts()
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
m_driver->flags = 1;
}

Expand Down
4 changes: 2 additions & 2 deletions Kernel/Bus/VirtIO/VirtIORNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void VirtIORNG::handle_queue_update(u16 queue_index)
size_t available_entropy = 0, used;
auto& queue = get_queue(REQUESTQ);
{
ScopedSpinlock lock(queue.lock());
SpinlockLocker lock(queue.lock());
auto chain = queue.pop_used_buffer_chain(used);
if (chain.is_empty())
return;
Expand All @@ -64,7 +64,7 @@ void VirtIORNG::handle_queue_update(u16 queue_index)
void VirtIORNG::request_entropy_from_host()
{
auto& queue = get_queue(REQUESTQ);
ScopedSpinlock lock(queue.lock());
SpinlockLocker lock(queue.lock());
VirtIOQueueChain chain(queue);
chain.add_buffer_to_chain(m_entropy_buffer->physical_page(0)->paddr(), PAGE_SIZE, BufferType::DeviceWritable);
supply_chain_and_notify(REQUESTQ, chain);
Expand Down
2 changes: 1 addition & 1 deletion Kernel/ConsoleDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Kernel::KResultOr<size_t> ConsoleDevice::write(FileDescription&, u64, const Kern

void ConsoleDevice::put_char(char ch)
{
Kernel::ScopedSpinlock lock(g_console_lock);
Kernel::SpinlockLocker lock(g_console_lock);
#ifdef CONSOLE_OUT_TO_BOCHS_DEBUG_PORT
IO::out8(IO::BOCHS_DEBUG_PORT, ch);
#endif
Expand Down
2 changes: 1 addition & 1 deletion Kernel/CoreDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ ByteBuffer CoreDump::create_notes_segment_data() const

KResult CoreDump::write()
{
ScopedSpinlock lock(m_process->address_space().get_lock());
SpinlockLocker lock(m_process->address_space().get_lock());
ProcessPagingScope scope(m_process);

ByteBuffer notes_segment = create_notes_segment_data();
Expand Down
10 changes: 5 additions & 5 deletions Kernel/Devices/AsyncDeviceRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ AsyncDeviceRequest::AsyncDeviceRequest(Device& device)
AsyncDeviceRequest::~AsyncDeviceRequest()
{
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
VERIFY(is_completed_result(m_result));
VERIFY(m_sub_requests_pending.is_empty());
}
Expand Down Expand Up @@ -63,7 +63,7 @@ auto AsyncDeviceRequest::wait(Time* timeout) -> RequestWaitResult

auto AsyncDeviceRequest::get_request_result() const -> RequestResult
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
return m_result;
}

Expand All @@ -74,7 +74,7 @@ void AsyncDeviceRequest::add_sub_request(NonnullRefPtr<AsyncDeviceRequest> sub_r
VERIFY(sub_request->m_parent_request == nullptr);
sub_request->m_parent_request = this;

ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
VERIFY(!is_completed_result(m_result));
m_sub_requests_pending.append(sub_request);
if (m_result == Started)
Expand All @@ -85,7 +85,7 @@ void AsyncDeviceRequest::sub_request_finished(AsyncDeviceRequest& sub_request)
{
bool all_completed;
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
VERIFY(m_result == Started);

if (m_sub_requests_pending.contains(sub_request)) {
Expand Down Expand Up @@ -131,7 +131,7 @@ void AsyncDeviceRequest::complete(RequestResult result)
VERIFY(result == Success || result == Failure || result == MemoryFault);
ScopedCritical critical;
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
VERIFY(m_result == Started);
m_result = result;
}
Expand Down
2 changes: 1 addition & 1 deletion 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(ScopedSpinlock<Spinlock<u8>>&& requests_lock)
void do_start(SpinlockLocker<Spinlock<u8>>&& requests_lock)
{
if (is_completed_result(m_result))
return;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ String Device::absolute_path(const FileDescription&) const

void Device::process_next_queued_request(Badge<AsyncDeviceRequest>, const AsyncDeviceRequest& completed_request)
{
ScopedSpinlock lock(m_requests_lock);
SpinlockLocker lock(m_requests_lock);
VERIFY(!m_requests.is_empty());
VERIFY(m_requests.first().ptr() == &completed_request);
m_requests.remove(m_requests.begin());
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Device : public File {
NonnullRefPtr<AsyncRequestType> make_request(Args&&... args)
{
auto request = adopt_ref(*new AsyncRequestType(*this, forward<Args>(args)...));
ScopedSpinlock lock(m_requests_lock);
SpinlockLocker lock(m_requests_lock);
bool was_empty = m_requests.is_empty();
m_requests.append(request);
if (was_empty)
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Devices/HID/I8042Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ UNMAP_AFTER_INIT void I8042Controller::detect_devices()
{
u8 configuration;
{
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
// Disable devices
do_wait_then_write(I8042_STATUS, 0xad);
do_wait_then_write(I8042_STATUS, 0xa7); // ignored if it doesn't exist
Expand Down Expand Up @@ -103,7 +103,7 @@ UNMAP_AFTER_INIT void I8042Controller::detect_devices()
m_first_port_available = false;
configuration &= ~1;
configuration |= 1 << 4;
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
do_wait_then_write(I8042_STATUS, 0x60);
do_wait_then_write(I8042_BUFFER, configuration);
}
Expand All @@ -116,7 +116,7 @@ UNMAP_AFTER_INIT void I8042Controller::detect_devices()
dbgln("I8042: Mouse device failed to initialize, disable");
m_second_port_available = false;
configuration |= 1 << 5;
ScopedSpinlock lock(m_lock);
SpinlockLocker lock(m_lock);
do_wait_then_write(I8042_STATUS, 0x60);
do_wait_then_write(I8042_BUFFER, configuration);
}
Expand Down
Loading

0 comments on commit c922a7d

Please sign in to comment.