summaryrefslogtreecommitdiffstats
path: root/src/core/core_cpu.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-05-03 06:16:12 +0200
committerbunnei <bunneidev@gmail.com>2018-05-11 01:34:47 +0200
commitcba69fdcd439c5f225bbddf1dad70e6326edd0dc (patch)
treeb608addf14d16c634cbe99a04e7931adfb2dbf31 /src/core/core_cpu.cpp
parentcore: Implement multicore support. (diff)
downloadyuzu-cba69fdcd439c5f225bbddf1dad70e6326edd0dc.tar
yuzu-cba69fdcd439c5f225bbddf1dad70e6326edd0dc.tar.gz
yuzu-cba69fdcd439c5f225bbddf1dad70e6326edd0dc.tar.bz2
yuzu-cba69fdcd439c5f225bbddf1dad70e6326edd0dc.tar.lz
yuzu-cba69fdcd439c5f225bbddf1dad70e6326edd0dc.tar.xz
yuzu-cba69fdcd439c5f225bbddf1dad70e6326edd0dc.tar.zst
yuzu-cba69fdcd439c5f225bbddf1dad70e6326edd0dc.zip
Diffstat (limited to 'src/core/core_cpu.cpp')
-rw-r--r--src/core/core_cpu.cpp29
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 @@
namespace Core {
+void CpuBarrier::NotifyEnd() {
+ std::unique_lock<std::mutex> lock(mutex);
+ end = true;
+ condition.notify_all();
+}
+
+bool CpuBarrier::Rendezvous() {
+ if (end) {
+ return false;
+ } else {
+ std::unique_lock<std::mutex> 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<CpuBarrier> 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<CpuBarrier> 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