mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-25 04:46:27 -05:00
bootmanager: Use std::stop_source for stopping emulation
Use its std::stop_token to abort shader cache loading. Using std::stop_token instead of std::atomic_bool allows the usage of other utilities like std::stop_callback.
This commit is contained in:
parent
0485b8e84b
commit
4009ae1da2
8 changed files with 18 additions and 18 deletions
|
@ -4,10 +4,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <stop_token>
|
||||
#include "common/common_types.h"
|
||||
#include "video_core/engines/fermi_2d.h"
|
||||
#include "video_core/gpu.h"
|
||||
|
@ -123,7 +123,7 @@ public:
|
|||
virtual void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {}
|
||||
|
||||
/// Initialize disk cached resources for the game being emulated
|
||||
virtual void LoadDiskResources(u64 title_id, const std::atomic_bool& stop_loading,
|
||||
virtual void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||
const DiskResourceLoadCallback& callback) {}
|
||||
|
||||
/// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
|
||||
|
|
|
@ -351,7 +351,7 @@ void RasterizerOpenGL::SetupShaders(bool is_indexed) {
|
|||
}
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::LoadDiskResources(u64 title_id, const std::atomic_bool& stop_loading,
|
||||
void RasterizerOpenGL::LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||
const VideoCore::DiskResourceLoadCallback& callback) {
|
||||
shader_cache.LoadDiskCache(title_id, stop_loading, callback);
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public:
|
|||
const Tegra::Engines::Fermi2D::Config& copy_config) override;
|
||||
bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
|
||||
u32 pixel_stride) override;
|
||||
void LoadDiskResources(u64 title_id, const std::atomic_bool& stop_loading,
|
||||
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||
const VideoCore::DiskResourceLoadCallback& callback) override;
|
||||
|
||||
/// Returns true when there are commands queued to the OpenGL server.
|
||||
|
|
|
@ -331,7 +331,7 @@ ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer_,
|
|||
|
||||
ShaderCacheOpenGL::~ShaderCacheOpenGL() = default;
|
||||
|
||||
void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, const std::atomic_bool& stop_loading,
|
||||
void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, std::stop_token stop_loading,
|
||||
const VideoCore::DiskResourceLoadCallback& callback) {
|
||||
disk_cache.BindTitleID(title_id);
|
||||
const std::optional transferable = disk_cache.LoadTransferable();
|
||||
|
@ -372,7 +372,7 @@ void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, const std::atomic_bool& stop
|
|||
const auto scope = context->Acquire();
|
||||
|
||||
for (std::size_t i = begin; i < end; ++i) {
|
||||
if (stop_loading) {
|
||||
if (stop_loading.stop_requested()) {
|
||||
return;
|
||||
}
|
||||
const auto& entry = (*transferable)[i];
|
||||
|
@ -435,7 +435,7 @@ void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, const std::atomic_bool& stop
|
|||
precompiled_cache_altered = true;
|
||||
return;
|
||||
}
|
||||
if (stop_loading) {
|
||||
if (stop_loading.stop_requested()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ public:
|
|||
~ShaderCacheOpenGL() override;
|
||||
|
||||
/// Loads disk cache for the current game
|
||||
void LoadDiskCache(u64 title_id, const std::atomic_bool& stop_loading,
|
||||
void LoadDiskCache(u64 title_id, std::stop_token stop_loading,
|
||||
const VideoCore::DiskResourceLoadCallback& callback);
|
||||
|
||||
/// Gets the current specified shader stage program
|
||||
|
|
|
@ -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; });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ int main(int argc, char** argv) {
|
|||
system.GPU().Start();
|
||||
|
||||
system.Renderer().ReadRasterizer()->LoadDiskResources(
|
||||
system.CurrentProcess()->GetTitleID(), false,
|
||||
system.CurrentProcess()->GetTitleID(), std::stop_token{},
|
||||
[](VideoCore::LoadCallbackStage, size_t value, size_t total) {});
|
||||
|
||||
void(system.Run());
|
||||
|
|
Loading…
Reference in a new issue