| 74 | } |
| 75 | |
| 76 | auto TestEnvironmentState::GetCoreIdForThread(std::thread::id tid) -> size_t { |
| 77 | std::lock_guard<std::mutex> lock(map_mutex_); |
| 78 | auto it = thread_to_core_map_.find(tid); |
| 79 | if (it != thread_to_core_map_.end()) { |
| 80 | return it->second; |
| 81 | } |
| 82 | |
| 83 | // 自动分配一个核心 ID (兼容旧行为) |
| 84 | if (next_core_id_ >= cores_.size()) { |
| 85 | // 如果核心未初始化,默认创建单核环境 |
| 86 | if (cores_.empty()) { |
| 87 | cores_.emplace_back(0); |
| 88 | } |
| 89 | next_core_id_ = 0; |
| 90 | } |
| 91 | |
| 92 | size_t new_id = next_core_id_; |
| 93 | thread_to_core_map_[tid] = new_id; |
| 94 | cores_[new_id].thread_id = tid; |
| 95 | next_core_id_ = (next_core_id_ + 1) % cores_.size(); |
| 96 | return new_id; |
| 97 | } |
| 98 | |
| 99 | auto TestEnvironmentState::GetCurrentCoreEnv() -> CoreEnvironment& { |
| 100 | auto tid = std::this_thread::get_id(); |
no test coverage detected