mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 16:07:45 +00:00
Kernel: Implement software context switching and Processor structure
Moving certain globals into a new Processor structure for each CPU allows us to eventually run an instance of the scheduler on each CPU.
This commit is contained in:
parent
10407061d2
commit
fb41d89384
22 changed files with 1002 additions and 513 deletions
|
@ -69,6 +69,42 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class RecursiveSpinLock
|
||||
{
|
||||
AK::Atomic<FlatPtr> m_lock{0};
|
||||
u32 m_recursions{0};
|
||||
|
||||
public:
|
||||
RecursiveSpinLock() = default;
|
||||
RecursiveSpinLock(const RecursiveSpinLock&) = delete;
|
||||
RecursiveSpinLock(RecursiveSpinLock&&) = delete;
|
||||
|
||||
ALWAYS_INLINE void lock()
|
||||
{
|
||||
FlatPtr cpu = FlatPtr(&Processor::current());
|
||||
FlatPtr expected = 0;
|
||||
while (!m_lock.compare_exchange_strong(expected, cpu, AK::memory_order_acq_rel)) {
|
||||
if (expected == cpu)
|
||||
break;
|
||||
expected = 0;
|
||||
}
|
||||
m_recursions++;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void unlock()
|
||||
{
|
||||
ASSERT(m_recursions > 0);
|
||||
ASSERT(m_lock.load(AK::memory_order_consume) == FlatPtr(&Processor::current()));
|
||||
if (--m_recursions == 0)
|
||||
m_lock.store(0, AK::memory_order_release);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool is_locked() const
|
||||
{
|
||||
return m_lock.load(AK::memory_order_consume) != 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename BaseType = u32, typename LockType = SpinLock<BaseType>>
|
||||
class ScopedSpinLock
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue