Kernel: Create RecursiveSpinLock and add it to Process

We now lock every function within Proccess, just to be sure.
Recursive lock allows us to use lock from the same thread even if
we already have the spinlock locked
This commit is contained in:
2023-03-24 01:32:35 +02:00
parent 5fd26b4ea8
commit 814f0b215d
4 changed files with 63 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
#include <kernel/SpinLock.h>
#include <kernel/Thread.h>
namespace Kernel
{
@@ -21,4 +22,35 @@ namespace Kernel
return m_lock;
}
void RecursiveSpinLock::lock()
{
// FIXME: is this thread safe?
if (m_locker == Thread::current()->tid())
{
m_lock_depth++;
}
else
{
m_lock.lock();
ASSERT(m_locker == 0);
m_locker = Thread::current()->tid();
m_lock_depth = 1;
}
}
void RecursiveSpinLock::unlock()
{
m_lock_depth--;
if (m_lock_depth == 0)
{
m_locker = 0;
m_lock.unlock();
}
}
bool RecursiveSpinLock::is_locked() const
{
return m_lock.is_locked();
}
}