diff --git a/kernel/src/memory/KernelVM.cpp b/kernel/src/memory/KernelVM.cpp index 9506f53d..74bbfa37 100644 --- a/kernel/src/memory/KernelVM.cpp +++ b/kernel/src/memory/KernelVM.cpp @@ -21,8 +21,6 @@ namespace KernelVM { void init() { - g_kernelvm_bitmap.init(); - auto kernelvm_bitmap = g_kernelvm_bitmap.lock(); kernelvm_bitmap->initialize(bitmap_memory, sizeof(bitmap_memory)); kernelvm_bitmap->clear(false); diff --git a/kernel/src/memory/MemoryManager.cpp b/kernel/src/memory/MemoryManager.cpp index f31194d6..b23c8f17 100644 --- a/kernel/src/memory/MemoryManager.cpp +++ b/kernel/src/memory/MemoryManager.cpp @@ -53,8 +53,6 @@ namespace MemoryManager MemoryMapIterator iter; MemoryMapEntry entry; - g_frame_bitmap.init(); - const auto largest_free_entry = iter.largest_free(); expect(largest_free_entry.is_free(), "We were given a largest free memory region that isn't even free!"); diff --git a/kernel/src/thread/Spinlock.cpp b/kernel/src/thread/Spinlock.cpp index 7c70e08f..8184a029 100644 --- a/kernel/src/thread/Spinlock.cpp +++ b/kernel/src/thread/Spinlock.cpp @@ -4,18 +4,18 @@ void Spinlock::lock() { - int expected = -1; - while (!m_lock.compare_exchange_strong(expected, 0)) + int expected = 0; + while (!m_lock.compare_exchange_strong(expected, 1)) { - expected = -1; + expected = 0; CPU::pause(); } } void Spinlock::unlock() { - int expected = 0; - if (!m_lock.compare_exchange_strong(expected, -1)) + int expected = 1; + if (!m_lock.compare_exchange_strong(expected, 0)) { kwarnln("Spinlock::unlock() called on an unlocked lock with value %d", expected); } diff --git a/kernel/src/thread/Spinlock.h b/kernel/src/thread/Spinlock.h index 984b6ce3..3553752c 100644 --- a/kernel/src/thread/Spinlock.h +++ b/kernel/src/thread/Spinlock.h @@ -9,17 +9,11 @@ class Spinlock bool is_locked() const { - return m_lock.load() != -1; - } - - // Call this before use if the Spinlock is a global variable. - void init() - { - m_lock = -1; + return m_lock.load() != 0; } private: - Atomic m_lock{-1}; + Atomic m_lock{0}; }; template class LockedValue @@ -68,12 +62,6 @@ template class LockedValue { } - // Call this before use if the LockedValue is a global variable. - void init() - { - m_lock.init(); - } - LockedValueGuard lock() { m_lock.lock();