diff options
Diffstat (limited to 'src')
| -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: | |||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | bool IsRunning() const { | 63 | bool IsRunning() const { |
| 64 | std::scoped_lock lock(mutex); | ||
| 64 | return is_running; | 65 | return is_running; |
| 65 | } | 66 | } |
| 66 | 67 | ||
| @@ -130,9 +131,10 @@ public: | |||
| 130 | } | 131 | } |
| 131 | 132 | ||
| 132 | void RunEmulation() { | 133 | void RunEmulation() { |
| 133 | std::unique_lock lock(mutex); | 134 | { |
| 134 | 135 | std::scoped_lock lock(mutex); | |
| 135 | is_running = true; | 136 | is_running = true; |
| 137 | } | ||
| 136 | 138 | ||
| 137 | void(system.Run()); | 139 | void(system.Run()); |
| 138 | 140 | ||
| @@ -140,9 +142,19 @@ public: | |||
| 140 | system.InitializeDebugger(); | 142 | system.InitializeDebugger(); |
| 141 | } | 143 | } |
| 142 | 144 | ||
| 143 | while (!cv.wait_for(lock, std::chrono::seconds(1), [&]() { return !is_running; })) { | 145 | while (true) { |
| 144 | std::scoped_lock perf_stats_lock(perf_stats_mutex); | 146 | { |
| 145 | perf_stats = system.GetAndResetPerfStats(); | 147 | std::unique_lock lock(mutex); |
| 148 | if (cv.wait_for(lock, std::chrono::seconds(1), [&]() { return !is_running; })) { | ||
| 149 | // Emulation halted. | ||
| 150 | break; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | { | ||
| 154 | // Refresh performance stats. | ||
| 155 | std::scoped_lock perf_stats_lock(perf_stats_mutex); | ||
| 156 | perf_stats = system.GetAndResetPerfStats(); | ||
| 157 | } | ||
| 146 | } | 158 | } |
| 147 | } | 159 | } |
| 148 | 160 | ||
| @@ -156,12 +168,13 @@ private: | |||
| 156 | Core::System system; | 168 | Core::System system; |
| 157 | 169 | ||
| 158 | Core::PerfStatsResults perf_stats{}; | 170 | Core::PerfStatsResults perf_stats{}; |
| 159 | mutable std::mutex perf_stats_mutex; | ||
| 160 | 171 | ||
| 161 | std::unique_ptr<EmuWindow_Android> window; | 172 | std::unique_ptr<EmuWindow_Android> window; |
| 162 | std::mutex mutex; | ||
| 163 | std::condition_variable_any cv; | 173 | std::condition_variable_any cv; |
| 164 | bool is_running{}; | 174 | bool is_running{}; |
| 175 | |||
| 176 | mutable std::mutex perf_stats_mutex; | ||
| 177 | mutable std::mutex mutex; | ||
| 165 | }; | 178 | }; |
| 166 | 179 | ||
| 167 | /*static*/ EmulationSession EmulationSession::s_instance; | 180 | /*static*/ EmulationSession EmulationSession::s_instance; |