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:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user