Merge pull request #6508 from ReinUsesLisp/bootmanager-stop-token

bootmanager: Use std::stop_source for stopping emulation
This commit is contained in:
Mai M
2021-06-23 02:35:42 -04:00
committed by GitHub
8 changed files with 18 additions and 18 deletions

View File

@ -51,11 +51,11 @@ void EmuThread::run() {
Common::SetCurrentThreadName(name.c_str());
auto& system = Core::System::GetInstance();
auto& gpu = system.GPU();
auto stop_token = stop_source.get_token();
system.RegisterHostThread();
auto& gpu = system.GPU();
// Main process has been loaded. Make the context current to this thread and begin GPU and CPU
// execution.
gpu.Start();
@ -65,7 +65,7 @@ void EmuThread::run() {
emit LoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0);
system.Renderer().ReadRasterizer()->LoadDiskResources(
system.CurrentProcess()->GetTitleID(), stop_run,
system.CurrentProcess()->GetTitleID(), stop_token,
[this](VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total) {
emit LoadProgress(stage, value, total);
});
@ -78,7 +78,7 @@ void EmuThread::run() {
// so that the DebugModeLeft signal can be emitted before the
// next execution step
bool was_active = false;
while (!stop_run) {
while (!stop_token.stop_requested()) {
if (running) {
if (was_active) {
emit DebugModeLeft();
@ -100,7 +100,7 @@ void EmuThread::run() {
}
running_guard = false;
if (!stop_run) {
if (!stop_token.stop_requested()) {
was_active = true;
emit DebugModeEntered();
}
@ -108,7 +108,7 @@ void EmuThread::run() {
UNIMPLEMENTED();
} else {
std::unique_lock lock{running_mutex};
running_cv.wait(lock, [this] { return IsRunning() || exec_step || stop_run; });
running_cv.wait(lock, stop_token, [this] { return IsRunning() || exec_step; });
}
}

View File

@ -89,16 +89,16 @@ public:
* Requests for the emulation thread to stop running
*/
void RequestStop() {
stop_run = true;
stop_source.request_stop();
SetRunning(false);
}
private:
bool exec_step = false;
bool running = false;
std::atomic_bool stop_run{false};
std::stop_source stop_source;
std::mutex running_mutex;
std::condition_variable running_cv;
std::condition_variable_any running_cv;
Common::Event running_wait{};
std::atomic_bool running_guard{false};