diff options
Diffstat (limited to 'src/core/cpu_manager.cpp')
| -rw-r--r-- | src/core/cpu_manager.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 0dd4c2196..04a11f444 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp | |||
| @@ -20,23 +20,20 @@ namespace Core { | |||
| 20 | CpuManager::CpuManager(System& system_) : system{system_} {} | 20 | CpuManager::CpuManager(System& system_) : system{system_} {} |
| 21 | CpuManager::~CpuManager() = default; | 21 | CpuManager::~CpuManager() = default; |
| 22 | 22 | ||
| 23 | void CpuManager::ThreadStart(std::stop_token stop_token, CpuManager& cpu_manager, | ||
| 24 | std::size_t core) { | ||
| 25 | cpu_manager.RunThread(core); | ||
| 26 | } | ||
| 27 | |||
| 28 | void CpuManager::Initialize() { | 23 | void CpuManager::Initialize() { |
| 29 | num_cores = is_multicore ? Core::Hardware::NUM_CPU_CORES : 1; | 24 | num_cores = is_multicore ? Core::Hardware::NUM_CPU_CORES : 1; |
| 30 | gpu_barrier = std::make_unique<Common::Barrier>(num_cores + 1); | 25 | gpu_barrier = std::make_unique<Common::Barrier>(num_cores + 1); |
| 31 | 26 | ||
| 32 | for (std::size_t core = 0; core < num_cores; core++) { | 27 | for (std::size_t core = 0; core < num_cores; core++) { |
| 33 | core_data[core].host_thread = std::jthread(ThreadStart, std::ref(*this), core); | 28 | core_data[core].host_thread = |
| 29 | std::jthread([this, core](std::stop_token token) { RunThread(token, core); }); | ||
| 34 | } | 30 | } |
| 35 | } | 31 | } |
| 36 | 32 | ||
| 37 | void CpuManager::Shutdown() { | 33 | void CpuManager::Shutdown() { |
| 38 | for (std::size_t core = 0; core < num_cores; core++) { | 34 | for (std::size_t core = 0; core < num_cores; core++) { |
| 39 | if (core_data[core].host_thread.joinable()) { | 35 | if (core_data[core].host_thread.joinable()) { |
| 36 | core_data[core].host_thread.request_stop(); | ||
| 40 | core_data[core].host_thread.join(); | 37 | core_data[core].host_thread.join(); |
| 41 | } | 38 | } |
| 42 | } | 39 | } |
| @@ -184,7 +181,7 @@ void CpuManager::ShutdownThread() { | |||
| 184 | UNREACHABLE(); | 181 | UNREACHABLE(); |
| 185 | } | 182 | } |
| 186 | 183 | ||
| 187 | void CpuManager::RunThread(std::size_t core) { | 184 | void CpuManager::RunThread(std::stop_token token, std::size_t core) { |
| 188 | /// Initialization | 185 | /// Initialization |
| 189 | system.RegisterCoreThread(core); | 186 | system.RegisterCoreThread(core); |
| 190 | std::string name; | 187 | std::string name; |
| @@ -206,7 +203,9 @@ void CpuManager::RunThread(std::size_t core) { | |||
| 206 | }); | 203 | }); |
| 207 | 204 | ||
| 208 | // Running | 205 | // Running |
| 209 | gpu_barrier->Sync(); | 206 | if (!gpu_barrier->Sync(token)) { |
| 207 | return; | ||
| 208 | } | ||
| 210 | 209 | ||
| 211 | if (!is_async_gpu && !is_multicore) { | 210 | if (!is_async_gpu && !is_multicore) { |
| 212 | system.GPU().ObtainContext(); | 211 | system.GPU().ObtainContext(); |