Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Kernel: Rename SpinLock to Mutex, add name to locks
Browse files Browse the repository at this point in the history
  • Loading branch information
byteduck committed Feb 8, 2024
1 parent 4a06d97 commit bcf0d6f
Show file tree
Hide file tree
Showing 47 changed files with 109 additions and 105 deletions.
2 changes: 1 addition & 1 deletion kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ SET(KERNEL_SRCS
tasking/Process.cpp
tasking/Thread.cpp
tasking/Lock.cpp
tasking/SpinLock.cpp
tasking/Mutex.cpp
tasking/ProcessArgs.cpp
tasking/Blocker.cpp
tasking/WaitBlocker.cpp
Expand Down
1 change: 0 additions & 1 deletion kernel/User.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <kernel/kstd/types.h>
#include <kernel/kstd/vector.hpp>
#include <kernel/tasking/SpinLock.h>
#include "Result.hpp"
#include <kernel/kstd/unix_types.h>

Expand Down
4 changes: 2 additions & 2 deletions kernel/device/BochsVGADevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "VGADevice.h"
#include <kernel/pci/PCI.h>
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>

#define VBE_DISPI_INDEX_ID 0
#define VBE_DISPI_INDEX_XRES 1
Expand Down Expand Up @@ -84,7 +84,7 @@ class BochsVGADevice: public VGADevice {
uint16_t display_width = VBE_DEFAULT_WIDTH;
uint16_t display_height = VBE_DEFAULT_HEIGHT;

SpinLock _lock;
Mutex _lock = Mutex("BochsVGADevice");
};


2 changes: 1 addition & 1 deletion kernel/device/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <kernel/kstd/KLog.h>

kstd::vector<kstd::Arc<Device>> Device::_devices;
SpinLock Device::_lock;
Mutex Device::_lock("Device");

void Device::init() {
new ZeroDevice();
Expand Down
4 changes: 2 additions & 2 deletions kernel/device/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <kernel/filesystem/File.h>
#include <kernel/kstd/vector.hpp>
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>

class Device: public File {
public:
Expand All @@ -44,7 +44,7 @@ class Device: public File {

private:
static kstd::vector<kstd::Arc<Device>> _devices;
static SpinLock _lock;
static Mutex _lock;

unsigned _major = 0;
unsigned _minor = 0;
Expand Down
2 changes: 1 addition & 1 deletion kernel/device/DiskDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

size_t DiskDevice::s_used_cache_memory = 0;
kstd::vector<DiskDevice*> DiskDevice::s_disk_devices;
SpinLock DiskDevice::s_disk_devices_lock;
Mutex DiskDevice::s_disk_devices_lock("DiskDevices");

DiskDevice::DiskDevice(unsigned int major, unsigned int minor): BlockDevice(major, minor) {
s_disk_devices.push_back(this);
Expand Down
6 changes: 3 additions & 3 deletions kernel/device/DiskDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ class DiskDevice: public BlockDevice {
size_t start_block;
Time last_used = Time::now();
bool dirty = false;
SpinLock lock;
Mutex lock {"BlockCacheRegion"};
};

// Static
static SpinLock s_disk_devices_lock;
static Mutex s_disk_devices_lock;
static size_t s_used_cache_memory;
static kstd::vector<DiskDevice*> s_disk_devices;

kstd::LRUCache<size_t, kstd::Arc<BlockCacheRegion>> _cache_regions;
kstd::Arc<BlockCacheRegion> get_cache_region(size_t block);
inline size_t blocks_per_cache_region() { return PAGE_SIZE / block_size(); }
inline size_t block_cache_region_start(size_t block) { return block - (block % blocks_per_cache_region()); }
SpinLock _cache_lock;
Mutex _cache_lock {"DiskDeviceCache"};
};

2 changes: 1 addition & 1 deletion kernel/device/KernelLogDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ssize_t KernelLogDevice::write(FileDescriptor& fd, size_t offset, SafePointer<ui
}

auto* cur_proc = TaskManager::current_process();
extern SpinLock printf_lock;
extern Mutex printf_lock;

LOCK(printf_lock);
printf("%s[%d.%s] %s(%d) [%s] ", log_colors[log_level], (int)time.tv_sec, usec_buf, cur_proc->name().c_str(), cur_proc->pid(), log_names[log_level]);
Expand Down
4 changes: 2 additions & 2 deletions kernel/device/MultibootVGADevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#pragma once

#include "VGADevice.h"
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>

class MultibootVGADevice: VGADevice {
public:
Expand Down Expand Up @@ -50,7 +50,7 @@ class MultibootVGADevice: VGADevice {
uint32_t framebuffer_height;
uint32_t framebuffer_bpp;
bool textmode;
SpinLock _lock;
Mutex _lock {"MultibootVGADevice"};
};


4 changes: 2 additions & 2 deletions kernel/device/PATADevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <kernel/interrupt/IRQHandler.h>
#include "ATA.h"
#include "DiskDevice.h"
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>
#include <kernel/memory/MemoryManager.h>

#define ATA_MAX_SECTORS_AT_ONCE (PAGE_SIZE / 512)
Expand Down Expand Up @@ -87,7 +87,7 @@ class PATADevice: public IRQHandler, public DiskDevice {
volatile bool _got_irq = false;

//Lock
SpinLock _lock;
Mutex _lock {"PATADevice"};
};


4 changes: 2 additions & 2 deletions kernel/filesystem/FileBasedFilesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "Filesystem.h"
#include "../kstd/LRUCache.h"
#include <kernel/time/Time.h>
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>
#include <kernel/kstd/vector.hpp>

class FileBasedFilesystem: public Filesystem {
Expand Down Expand Up @@ -61,7 +61,7 @@ class FileBasedFilesystem: public Filesystem {

private:
kstd::LRUCache<ino_t, kstd::Arc<Inode>> m_inode_cache;
SpinLock m_inode_cache_lock;
Mutex m_inode_cache_lock {"InodeCache"};
};


4 changes: 2 additions & 2 deletions kernel/filesystem/FileDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <kernel/kstd/Arc.h>
#include <kernel/kstd/string.h>
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>
#include <kernel/kstd/unix_types.h>
#include "File.h"
#include <kernel/memory/SafePointer.h>
Expand Down Expand Up @@ -81,7 +81,7 @@ class FileDescriptor {
off_t _seek {0};
bool _is_fifo_writer = false;

SpinLock lock;
Mutex lock {"FileDescriptor"};
};


4 changes: 2 additions & 2 deletions kernel/filesystem/Inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <kernel/kstd/unix_types.h>
#include <kernel/kstd/Arc.h>
#include <kernel/Result.hpp>
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>
#include "InodeMetadata.h"
#include <kernel/kstd/Iteration.h>
#include <kernel/memory/SafePointer.h>
Expand Down Expand Up @@ -67,7 +67,7 @@ public :

protected:
InodeMetadata _metadata;
SpinLock lock, m_vmobject_lock;
Mutex lock {"Inode"}, m_vmobject_lock {"Inode::VMObject"};
kstd::Weak<InodeVMObject> m_shared_vm_object;
bool _exists = true;
};
Expand Down
4 changes: 2 additions & 2 deletions kernel/filesystem/Pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <kernel/memory/MemoryManager.h>
#include <kernel/filesystem/File.h>
#include <kernel/kstd/circular_queue.hpp>
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>

#define PIPE_SIZE PAGE_SIZE

Expand All @@ -48,7 +48,7 @@ class Pipe: public File {
size_t _readers = 0;
size_t _writers = 0;
BooleanBlocker _blocker;
SpinLock _lock;
Mutex _lock {"Pipe"};
};


4 changes: 2 additions & 2 deletions kernel/filesystem/ext2/Ext2Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#pragma once

#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>
#include <kernel/filesystem/FileBasedFilesystem.h>
#include <kernel/Result.hpp>
#include <kernel/kstd/vector.hpp>
Expand Down Expand Up @@ -81,7 +81,7 @@ class Ext2Filesystem: public FileBasedFilesystem {
size_t block_pointers_per_block;

private:
SpinLock ext2lock;
Mutex ext2lock {"Ext2Filesystem"};

//Block stuff
Ext2BlockGroup** block_groups = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions kernel/filesystem/procfs/ProcFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <kernel/filesystem/Filesystem.h>
#include "ProcFSInodeType.h"
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>
#include <kernel/kstd/vector.hpp>

#define PROCFS_FSID 1
Expand Down Expand Up @@ -50,7 +50,7 @@ class ProcFS: public Filesystem {
friend class ProcFSInode;
static ProcFS* _instance;

SpinLock lock;
Mutex lock {"ProcFS"};
kstd::vector<ProcFSEntry> entries;
kstd::Arc<ProcFSInode> root_inode;
ino_t cinode_id;
Expand Down
4 changes: 2 additions & 2 deletions kernel/filesystem/ptyfs/PTYFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#pragma once

#include <kernel/filesystem/Filesystem.h>
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>
#include <kernel/kstd/vector.hpp>

#define PTYFS_FSID 4
Expand All @@ -44,7 +44,7 @@ class PTYFS: public Filesystem {
private:
friend class PTYFSInode;
kstd::vector<kstd::Arc<PTYFSInode>> _entries;
SpinLock _lock;
Mutex _lock {"PTYFS"};
};


4 changes: 2 additions & 2 deletions kernel/filesystem/socketfs/SocketFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <kernel/filesystem/Filesystem.h>
#include "socketfs_defines.h"
#include <kernel/kstd/vector.hpp>
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>

#define SOCKETFS_FSID 3

Expand Down Expand Up @@ -65,7 +65,7 @@ class SocketFS: public Filesystem {
friend class SocketFSInode;
kstd::vector<kstd::Arc<SocketFSInode>> sockets;
kstd::Arc<SocketFSInode> root_entry;
SpinLock lock;
Mutex lock {"SocketFS"};

};

Expand Down
4 changes: 2 additions & 2 deletions kernel/filesystem/socketfs/SocketFSClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <kernel/kstd/Arc.h>
#include <kernel/kstd/queue.hpp>
#include <kernel/kstd/unix_types.h>
#include <kernel/tasking/SpinLock.h>
#include <kernel/tasking/Mutex.h>

class Process;
class SocketFSClient {
Expand All @@ -32,7 +32,7 @@ class SocketFSClient {
sockid_t id;
pid_t pid;
kstd::queue<uint8_t> data_queue;
SpinLock data_lock;
Mutex data_lock {"SocketFSClient"};
BooleanBlocker blocker;
};

2 changes: 1 addition & 1 deletion kernel/filesystem/socketfs/SocketFSInode.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SocketFSInode: public Inode {
[[nodiscard]] kstd::Arc<SocketFSClient> get_client(const FileDescriptor* fd) const;

kstd::vector<kstd::Arc<SocketFSClient>> m_clients;
mutable SpinLock m_clients_lock;
mutable Mutex m_clients_lock {"SocketFSInode::Clients"};

kstd::Arc<SocketFSClient> host;
DirectoryEntry dir_entry;
Expand Down
4 changes: 2 additions & 2 deletions kernel/kstd/KLog.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "KLog.h"
#include "kstdio.h"
#include "../tasking/SpinLock.h"
#include "../tasking/Mutex.h"
#include <kernel/time/TimeManager.h>

extern SpinLock printf_lock;
extern Mutex printf_lock;
void klog_print(const char* component, const char* color, const char* type, const char* fmt, va_list list) {
auto time = TimeManager::uptime();
char* usec_buf = "0000000";
Expand Down
2 changes: 1 addition & 1 deletion kernel/kstd/bits/RefCount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* Copyright © 2016-2022 Byteduck */

#include "RefCount.h"
#include "../../tasking/SpinLock.h"
#include "../../tasking/Mutex.h"

using namespace kstd;

Expand Down
2 changes: 1 addition & 1 deletion kernel/kstd/kstdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void print(const char* str){
serial_putch(*(str++));
}

SpinLock printf_lock;
Mutex printf_lock {"printf"};
void printf(const char* fmt, ...) {
va_list list;
va_start(list, fmt);
Expand Down
2 changes: 1 addition & 1 deletion kernel/memory/AnonymousVMObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "MemoryManager.h"
#include "../kstd/cstring.h"

SpinLock AnonymousVMObject::s_shared_lock;
Mutex AnonymousVMObject::s_shared_lock {"AnonymousVMObject::Shared"};
int AnonymousVMObject::s_cur_shm_id = 1;
kstd::map<int, kstd::Weak<AnonymousVMObject>> AnonymousVMObject::s_shared_objects;

Expand Down
4 changes: 2 additions & 2 deletions kernel/memory/AnonymousVMObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "../Result.hpp"
#include "../kstd/map.hpp"
#include "../kstd/unix_types.h"
#include "../tasking/SpinLock.h"
#include "../tasking/Mutex.h"
#include "VMRegion.h"

class AnonymousVMObject: public VMObject {
Expand Down Expand Up @@ -79,7 +79,7 @@ class AnonymousVMObject: public VMObject {

explicit AnonymousVMObject(kstd::string name, kstd::vector<PageIndex> physical_pages, bool cow);

static SpinLock s_shared_lock;
static Mutex s_shared_lock;
static int s_cur_shm_id;
static kstd::map<int, kstd::Weak<AnonymousVMObject>> s_shared_objects;

Expand Down
2 changes: 1 addition & 1 deletion kernel/memory/InodeVMObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class InodeVMObject: public VMObject {
ResultRet<bool> read_page_if_needed(size_t index);

kstd::Arc<Inode> inode() const { return m_inode; }
SpinLock& lock() { return m_page_lock; }
Mutex& lock() { return m_page_lock; }
Type type() const { return m_type; }
bool is_inode() const override { return true; }
ForkAction fork_action() const override {
Expand Down
4 changes: 2 additions & 2 deletions kernel/memory/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,11 @@ size_t MemoryManager::kernel_heap() const {
}

void liballoc_lock() {
MemoryManager::inst().liballoc_spinlock.acquire();
MemoryManager::inst().liballoc_lock.acquire();
}

void liballoc_unlock() {
MemoryManager::inst().liballoc_spinlock.release();
MemoryManager::inst().liballoc_lock.release();
}

void *liballoc_alloc(int pages) {
Expand Down
Loading

0 comments on commit bcf0d6f

Please sign in to comment.