Spinlock+LockedValue: Remove init() functions
Let's set the default (unlocked) value of Spinlock's underlying atomic to 0, so even if the constructor is not called it stays like that.
This commit is contained in:
parent
a63146a798
commit
283e641ece
@ -21,8 +21,6 @@ namespace KernelVM
|
|||||||
{
|
{
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
g_kernelvm_bitmap.init();
|
|
||||||
|
|
||||||
auto kernelvm_bitmap = g_kernelvm_bitmap.lock();
|
auto kernelvm_bitmap = g_kernelvm_bitmap.lock();
|
||||||
kernelvm_bitmap->initialize(bitmap_memory, sizeof(bitmap_memory));
|
kernelvm_bitmap->initialize(bitmap_memory, sizeof(bitmap_memory));
|
||||||
kernelvm_bitmap->clear(false);
|
kernelvm_bitmap->clear(false);
|
||||||
|
@ -53,8 +53,6 @@ namespace MemoryManager
|
|||||||
MemoryMapIterator iter;
|
MemoryMapIterator iter;
|
||||||
MemoryMapEntry entry;
|
MemoryMapEntry entry;
|
||||||
|
|
||||||
g_frame_bitmap.init();
|
|
||||||
|
|
||||||
const auto largest_free_entry = iter.largest_free();
|
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!");
|
expect(largest_free_entry.is_free(), "We were given a largest free memory region that isn't even free!");
|
||||||
|
@ -4,18 +4,18 @@
|
|||||||
|
|
||||||
void Spinlock::lock()
|
void Spinlock::lock()
|
||||||
{
|
{
|
||||||
int expected = -1;
|
int expected = 0;
|
||||||
while (!m_lock.compare_exchange_strong(expected, 0))
|
while (!m_lock.compare_exchange_strong(expected, 1))
|
||||||
{
|
{
|
||||||
expected = -1;
|
expected = 0;
|
||||||
CPU::pause();
|
CPU::pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spinlock::unlock()
|
void Spinlock::unlock()
|
||||||
{
|
{
|
||||||
int expected = 0;
|
int expected = 1;
|
||||||
if (!m_lock.compare_exchange_strong(expected, -1))
|
if (!m_lock.compare_exchange_strong(expected, 0))
|
||||||
{
|
{
|
||||||
kwarnln("Spinlock::unlock() called on an unlocked lock with value %d", expected);
|
kwarnln("Spinlock::unlock() called on an unlocked lock with value %d", expected);
|
||||||
}
|
}
|
||||||
|
@ -9,17 +9,11 @@ class Spinlock
|
|||||||
|
|
||||||
bool is_locked() const
|
bool is_locked() const
|
||||||
{
|
{
|
||||||
return m_lock.load() != -1;
|
return m_lock.load() != 0;
|
||||||
}
|
|
||||||
|
|
||||||
// Call this before use if the Spinlock is a global variable.
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
m_lock = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Atomic<int> m_lock{-1};
|
Atomic<int> m_lock{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> class LockedValue
|
template <typename T> class LockedValue
|
||||||
@ -68,12 +62,6 @@ template <typename T> class LockedValue
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call this before use if the LockedValue is a global variable.
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
m_lock.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
LockedValueGuard lock()
|
LockedValueGuard lock()
|
||||||
{
|
{
|
||||||
m_lock.lock();
|
m_lock.lock();
|
||||||
|
Loading…
Reference in New Issue
Block a user