From cba69fdcd439c5f225bbddf1dad70e6326edd0dc Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 3 May 2018 00:16:12 -0400 Subject: core: Support session close with multicore. --- src/core/core_cpu.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/core/core_cpu.cpp') diff --git a/src/core/core_cpu.cpp b/src/core/core_cpu.cpp index a556f12e9..bd9869d28 100644 --- a/src/core/core_cpu.cpp +++ b/src/core/core_cpu.cpp @@ -19,6 +19,30 @@ namespace Core { +void CpuBarrier::NotifyEnd() { + std::unique_lock lock(mutex); + end = true; + condition.notify_all(); +} + +bool CpuBarrier::Rendezvous() { + if (end) { + return false; + } else { + std::unique_lock lock(mutex); + + --cores_waiting; + if (!cores_waiting) { + cores_waiting = NUM_CPU_CORES; + condition.notify_all(); + return true; + } + + condition.wait(lock); + return true; + } +} + Cpu::Cpu(std::shared_ptr cpu_barrier, size_t core_index) : cpu_barrier{std::move(cpu_barrier)}, core_index{core_index} { @@ -38,7 +62,10 @@ Cpu::Cpu(std::shared_ptr cpu_barrier, size_t core_index) void Cpu::RunLoop(bool tight_loop) { // Wait for all other CPU cores to complete the previous slice, such that they run in lock-step - cpu_barrier->Rendezvous(); + if (!cpu_barrier->Rendezvous()) { + // If rendezvous failed, session has been killed + return; + } // If we don't have a currently active thread then don't execute instructions, // instead advance to the next event and try to yield to the next thread -- cgit v1.2.3