mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-26 08:42:45 +01:00
Scheduler: Protect on closed threads.
This commit is contained in:
parent
19847d4d42
commit
3de33348e4
1 changed files with 17 additions and 7 deletions
|
@ -604,7 +604,6 @@ void Scheduler::SwitchContextStep2() {
|
||||||
|
|
||||||
if (new_thread) {
|
if (new_thread) {
|
||||||
auto& cpu_core = system.ArmInterface(core_id);
|
auto& cpu_core = system.ArmInterface(core_id);
|
||||||
new_thread->context_guard.lock();
|
|
||||||
cpu_core.Lock();
|
cpu_core.Lock();
|
||||||
ASSERT_MSG(new_thread->GetSchedulingStatus() == ThreadSchedStatus::Runnable,
|
ASSERT_MSG(new_thread->GetSchedulingStatus() == ThreadSchedStatus::Runnable,
|
||||||
"Thread must be runnable.");
|
"Thread must be runnable.");
|
||||||
|
@ -685,13 +684,24 @@ void Scheduler::OnSwitch(void* this_scheduler) {
|
||||||
|
|
||||||
void Scheduler::SwitchToCurrent() {
|
void Scheduler::SwitchToCurrent() {
|
||||||
while (true) {
|
while (true) {
|
||||||
std::shared_ptr<Common::Fiber> next_context;
|
guard.lock();
|
||||||
if (current_thread != nullptr) {
|
selected_thread = selected_thread_set;
|
||||||
next_context = current_thread->GetHostContext();
|
current_thread = selected_thread;
|
||||||
} else {
|
guard.unlock();
|
||||||
next_context = idle_thread->GetHostContext();
|
while (!is_context_switch_pending) {
|
||||||
|
current_thread->context_guard.lock();
|
||||||
|
if (current_thread->GetSchedulingStatus() != ThreadSchedStatus::Runnable) {
|
||||||
|
current_thread->context_guard.unlock();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::shared_ptr<Common::Fiber> next_context;
|
||||||
|
if (current_thread != nullptr) {
|
||||||
|
next_context = current_thread->GetHostContext();
|
||||||
|
} else {
|
||||||
|
next_context = idle_thread->GetHostContext();
|
||||||
|
}
|
||||||
|
Common::Fiber::YieldTo(switch_fiber, next_context);
|
||||||
}
|
}
|
||||||
Common::Fiber::YieldTo(switch_fiber, next_context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue