diff options
author | bunnei <bunneidev@gmail.com> | 2023-01-26 04:00:11 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2023-06-03 09:05:28 +0200 |
commit | d553fd4c3aaa947588954751cb07197b5c58fa4c (patch) | |
tree | b08b72a3c0471efcb4d14d1d9d57f6b8f12f427d /src/android | |
parent | android: jni: native: Remove unnecessary atomic for is_running. (diff) | |
download | yuzu-d553fd4c3aaa947588954751cb07197b5c58fa4c.tar yuzu-d553fd4c3aaa947588954751cb07197b5c58fa4c.tar.gz yuzu-d553fd4c3aaa947588954751cb07197b5c58fa4c.tar.bz2 yuzu-d553fd4c3aaa947588954751cb07197b5c58fa4c.tar.lz yuzu-d553fd4c3aaa947588954751cb07197b5c58fa4c.tar.xz yuzu-d553fd4c3aaa947588954751cb07197b5c58fa4c.tar.zst yuzu-d553fd4c3aaa947588954751cb07197b5c58fa4c.zip |
Diffstat (limited to 'src/android')
-rw-r--r-- | src/android/app/src/main/jni/native.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index f1a70c35c..119c7cd01 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -61,6 +61,7 @@ public: } bool IsRunning() const { + std::scoped_lock lock(mutex); return is_running; } @@ -130,9 +131,10 @@ public: } void RunEmulation() { - std::unique_lock lock(mutex); - - is_running = true; + { + std::scoped_lock lock(mutex); + is_running = true; + } void(system.Run()); @@ -140,9 +142,19 @@ public: system.InitializeDebugger(); } - while (!cv.wait_for(lock, std::chrono::seconds(1), [&]() { return !is_running; })) { - std::scoped_lock perf_stats_lock(perf_stats_mutex); - perf_stats = system.GetAndResetPerfStats(); + while (true) { + { + std::unique_lock lock(mutex); + if (cv.wait_for(lock, std::chrono::seconds(1), [&]() { return !is_running; })) { + // Emulation halted. + break; + } + } + { + // Refresh performance stats. + std::scoped_lock perf_stats_lock(perf_stats_mutex); + perf_stats = system.GetAndResetPerfStats(); + } } } @@ -156,12 +168,13 @@ private: Core::System system; Core::PerfStatsResults perf_stats{}; - mutable std::mutex perf_stats_mutex; std::unique_ptr<EmuWindow_Android> window; - std::mutex mutex; std::condition_variable_any cv; bool is_running{}; + + mutable std::mutex perf_stats_mutex; + mutable std::mutex mutex; }; /*static*/ EmulationSession EmulationSession::s_instance; |