Kernel: Implement RecursivePrioritySpinLock

This locks won't allow locking from userspace thread if there is
kernel thread waiting to lock this.
This commit is contained in:
2023-12-07 13:18:21 +02:00
parent 669d55707e
commit 7c25e4ce5a
2 changed files with 78 additions and 1 deletions

View File

@@ -39,4 +39,24 @@ namespace Kernel
SpinLock m_lock;
};
}
class RecursivePrioritySpinLock
{
BAN_NON_COPYABLE(RecursivePrioritySpinLock);
BAN_NON_MOVABLE(RecursivePrioritySpinLock);
public:
RecursivePrioritySpinLock() = default;
void lock();
void unlock();
bool is_locked() const;
uint32_t lock_depth() const { return m_lock_depth; }
private:
pid_t m_locker = -1;
uint32_t m_queue_length = 0;
uint32_t m_lock_depth = 0;
SpinLock m_lock;
};
}