Kernel: Make entering and leaving critical sections atomic

We also need to store m_in_critical in the Thread upon switching,
and we need to restore it. This solves a problem where threads
moving between different processors could end up with an unexpected
value.
This commit is contained in:
Tom
2021-01-23 22:24:10 -07:00
committed by Andreas Kling
parent 33cdc1d2f1
commit f88a8b16d7
3 changed files with 25 additions and 13 deletions

View File

@@ -1065,6 +1065,9 @@ public:
m_is_active.store(active, AK::memory_order_release);
}
u32 saved_critical() const { return m_saved_critical; }
void save_critical(u32 critical) { m_saved_critical = critical; }
[[nodiscard]] bool is_active() const
{
return m_is_active.load(AK::MemoryOrder::memory_order_acquire);
@@ -1239,6 +1242,7 @@ private:
ThreadID m_tid { -1 };
TSS32 m_tss;
TrapFrame* m_current_trap { nullptr };
u32 m_saved_critical { 1 };
Atomic<u32> m_cpu { 0 };
u32 m_cpu_affinity { THREAD_AFFINITY_DEFAULT };
u32 m_ticks_left { 0 };