| 13 | extern "C" { |
| 14 | |
| 15 | void switch_to(cpu_io::CalleeSavedContext* prev_ctx, |
| 16 | cpu_io::CalleeSavedContext* next_ctx) { |
| 17 | auto* env_state = |
| 18 | test_env::TestEnvironmentState::GetCurrentThreadEnvironment(); |
| 19 | assert(env_state && |
| 20 | "TestEnvironmentState not set for current thread. " |
| 21 | "Did you forget to call SetCurrentThreadEnvironment()?"); |
| 22 | |
| 23 | auto& core_env = env_state->GetCurrentCoreEnv(); |
| 24 | |
| 25 | // 从上下文指针查找对应的任务 |
| 26 | auto* prev_task = env_state->FindTaskByContext(prev_ctx); |
| 27 | auto* next_task = env_state->FindTaskByContext(next_ctx); |
| 28 | |
| 29 | // 获取 PerCpu 数据 |
| 30 | auto& per_cpu = per_cpu::GetCurrentCore(); |
| 31 | |
| 32 | // 记录切换事件到环境层 |
| 33 | test_env::CoreEnvironment::SwitchEvent event; |
| 34 | event.timestamp = (per_cpu.sched_data ? per_cpu.sched_data->local_tick : 0); |
| 35 | event.from = prev_task; |
| 36 | event.to = next_task; |
| 37 | event.core_id = core_env.core_id; |
| 38 | core_env.switch_history.push_back(event); |
| 39 | |
| 40 | // 更新 PerCpu 的当前线程 |
| 41 | per_cpu.running_task = next_task; |
| 42 | } |
| 43 | |
| 44 | void kernel_thread_entry() {} |
| 45 | void trap_return(void*) {} |
no test coverage detected