mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +00:00
Kernel: Various context switch fixes
These changes solve a number of problems with the software context swithcing: * The scheduler lock really should be held throughout context switches * Transitioning from the initial (idle) thread to another needs to hold the scheduler lock * Transitioning from a dying thread to another also needs to hold the scheduler lock * Dying threads cannot necessarily be finalized if they haven't switched out of it yet, so flag them as active while a processor is running it (the Running state may be switched to Dying while it still is actually running)
This commit is contained in:
parent
49f5069b76
commit
2a82a25fec
9 changed files with 235 additions and 89 deletions
|
@ -73,8 +73,13 @@ void Lock::lock(Mode mode)
|
|||
// switch will happen, so yield.
|
||||
// The assumption is that if we call this from a critical section
|
||||
// that we DO want to temporarily leave it
|
||||
TemporaryChange change(Processor::current().in_critical(), 0u);
|
||||
u32 prev_flags;
|
||||
u32 prev_crit = Processor::current().clear_critical(prev_flags, !Processor::current().in_irq());
|
||||
|
||||
Scheduler::yield();
|
||||
|
||||
// Note, we may now be on a different CPU!
|
||||
Processor::current().restore_critical(prev_crit, prev_flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +110,13 @@ void Lock::unlock()
|
|||
// I don't know *who* is using "m_lock", so just yield.
|
||||
// The assumption is that if we call this from a critical section
|
||||
// that we DO want to temporarily leave it
|
||||
TemporaryChange change(Processor::current().in_critical(), 0u);
|
||||
u32 prev_flags;
|
||||
u32 prev_crit = Processor::current().clear_critical(prev_flags, false);
|
||||
|
||||
Scheduler::yield();
|
||||
|
||||
// Note, we may now be on a different CPU!
|
||||
Processor::current().restore_critical(prev_crit, prev_flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue