mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
android: jni: native: Refactor locking for is_running.
This commit is contained in:
parent
104ff475d2
commit
d553fd4c3a
1 changed files with 21 additions and 8 deletions
|
@ -61,6 +61,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsRunning() const {
|
bool IsRunning() const {
|
||||||
|
std::scoped_lock lock(mutex);
|
||||||
return is_running;
|
return is_running;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,9 +131,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunEmulation() {
|
void RunEmulation() {
|
||||||
std::unique_lock lock(mutex);
|
{
|
||||||
|
std::scoped_lock lock(mutex);
|
||||||
is_running = true;
|
is_running = true;
|
||||||
|
}
|
||||||
|
|
||||||
void(system.Run());
|
void(system.Run());
|
||||||
|
|
||||||
|
@ -140,11 +142,21 @@ public:
|
||||||
system.InitializeDebugger();
|
system.InitializeDebugger();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!cv.wait_for(lock, std::chrono::seconds(1), [&]() { return !is_running; })) {
|
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);
|
std::scoped_lock perf_stats_lock(perf_stats_mutex);
|
||||||
perf_stats = system.GetAndResetPerfStats();
|
perf_stats = system.GetAndResetPerfStats();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static EmulationSession s_instance;
|
static EmulationSession s_instance;
|
||||||
|
@ -156,12 +168,13 @@ private:
|
||||||
Core::System system;
|
Core::System system;
|
||||||
|
|
||||||
Core::PerfStatsResults perf_stats{};
|
Core::PerfStatsResults perf_stats{};
|
||||||
mutable std::mutex perf_stats_mutex;
|
|
||||||
|
|
||||||
std::unique_ptr<EmuWindow_Android> window;
|
std::unique_ptr<EmuWindow_Android> window;
|
||||||
std::mutex mutex;
|
|
||||||
std::condition_variable_any cv;
|
std::condition_variable_any cv;
|
||||||
bool is_running{};
|
bool is_running{};
|
||||||
|
|
||||||
|
mutable std::mutex perf_stats_mutex;
|
||||||
|
mutable std::mutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*static*/ EmulationSession EmulationSession::s_instance;
|
/*static*/ EmulationSession EmulationSession::s_instance;
|
||||||
|
|
Loading…
Reference in a new issue