diff options
| author | 2018-05-03 00:16:12 -0400 | |
|---|---|---|
| committer | 2018-05-10 19:34:47 -0400 | |
| commit | cba69fdcd439c5f225bbddf1dad70e6326edd0dc (patch) | |
| tree | b608addf14d16c634cbe99a04e7931adfb2dbf31 /src/core/core_cpu.cpp | |
| parent | core: Implement multicore support. (diff) | |
| download | yuzu-cba69fdcd439c5f225bbddf1dad70e6326edd0dc.tar.gz yuzu-cba69fdcd439c5f225bbddf1dad70e6326edd0dc.tar.xz yuzu-cba69fdcd439c5f225bbddf1dad70e6326edd0dc.zip | |
core: Support session close with multicore.
Diffstat (limited to 'src/core/core_cpu.cpp')
| -rw-r--r-- | src/core/core_cpu.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
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 @@ | |||
| 19 | 19 | ||
| 20 | namespace Core { | 20 | namespace Core { |
| 21 | 21 | ||
| 22 | void CpuBarrier::NotifyEnd() { | ||
| 23 | std::unique_lock<std::mutex> lock(mutex); | ||
| 24 | end = true; | ||
| 25 | condition.notify_all(); | ||
| 26 | } | ||
| 27 | |||
| 28 | bool CpuBarrier::Rendezvous() { | ||
| 29 | if (end) { | ||
| 30 | return false; | ||
| 31 | } else { | ||
| 32 | std::unique_lock<std::mutex> lock(mutex); | ||
| 33 | |||
| 34 | --cores_waiting; | ||
| 35 | if (!cores_waiting) { | ||
| 36 | cores_waiting = NUM_CPU_CORES; | ||
| 37 | condition.notify_all(); | ||
| 38 | return true; | ||
| 39 | } | ||
| 40 | |||
| 41 | condition.wait(lock); | ||
| 42 | return true; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 22 | Cpu::Cpu(std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index) | 46 | Cpu::Cpu(std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index) |
| 23 | : cpu_barrier{std::move(cpu_barrier)}, core_index{core_index} { | 47 | : cpu_barrier{std::move(cpu_barrier)}, core_index{core_index} { |
| 24 | 48 | ||
| @@ -38,7 +62,10 @@ Cpu::Cpu(std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index) | |||
| 38 | 62 | ||
| 39 | void Cpu::RunLoop(bool tight_loop) { | 63 | void Cpu::RunLoop(bool tight_loop) { |
| 40 | // Wait for all other CPU cores to complete the previous slice, such that they run in lock-step | 64 | // Wait for all other CPU cores to complete the previous slice, such that they run in lock-step |
| 41 | cpu_barrier->Rendezvous(); | 65 | if (!cpu_barrier->Rendezvous()) { |
| 66 | // If rendezvous failed, session has been killed | ||
| 67 | return; | ||
| 68 | } | ||
| 42 | 69 | ||
| 43 | // If we don't have a currently active thread then don't execute instructions, | 70 | // If we don't have a currently active thread then don't execute instructions, |
| 44 | // instead advance to the next event and try to yield to the next thread | 71 | // instead advance to the next event and try to yield to the next thread |