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:
Bananymous
2023-03-24 01:32:35 +02:00
parent 5fd26b4ea8
commit 814f0b215d
4 changed files with 63 additions and 1 deletions

View File

@@ -61,7 +61,7 @@ namespace Kernel
BAN::Vector<OpenFileDescription> m_open_files;
mutable SpinLock m_lock;
mutable RecursiveSpinLock m_lock;
pid_t m_pid = 0;
BAN::String m_working_directory;

View File

@@ -2,6 +2,8 @@
#include <BAN/NoCopyMove.h>
#include <sys/types.h>
namespace Kernel
{
@@ -20,4 +22,21 @@ namespace Kernel
int m_lock = 0;
};
class RecursiveSpinLock
{
BAN_NON_COPYABLE(RecursiveSpinLock);
BAN_NON_MOVABLE(RecursiveSpinLock);
public:
RecursiveSpinLock() = default;
void lock();
void unlock();
bool is_locked() const;
private:
pid_t m_locker = 0;
uint32_t m_lock_depth = 0;
SpinLock m_lock;
};
}