1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

Kernel: Add a blunt big process lock.

We can't have multiple threads in the same process running in the kernel
at the same time, so let's have a per-process lock that threads have to
acquire on syscall entry/exit (and yield while blocked.)
This commit is contained in:
Andreas Kling 2019-04-01 20:02:05 +02:00
parent 54ea35703a
commit d5a9f4596b
5 changed files with 37 additions and 0 deletions

View file

@ -26,6 +26,7 @@ public:
void lock();
void unlock();
bool unlock_if_locked();
const char* name() const { return m_name; }
@ -90,6 +91,32 @@ inline void Lock::unlock()
}
}
inline bool Lock::unlock_if_locked()
{
for (;;) {
if (CAS(&m_lock, 1, 0) == 0) {
if (m_level == 0) {
memory_barrier();
m_lock = 0;
return false;
}
ASSERT(m_holder == current);
ASSERT(m_level);
--m_level;
if (m_level) {
memory_barrier();
m_lock = 0;
return false;
}
m_holder = nullptr;
memory_barrier();
m_lock = 0;
return true;
}
Scheduler::donate_to(m_holder, m_name);
}
}
#define LOCKER(lock) Locker locker(lock)
template<typename T>