Skip to content

VERY experimental Nintendo Switch 2 emulator

C++

common: scope_exit: Implement mechanism for canceling a scope exit.

bunneib2b0f85b7dc2
diff --git a/src/common/scope_exit.h b/src/common/scope_exit.h
index 1176a72b19..68ef5f197e 100644
--- a/src/common/scope_exit.h
+++ b/src/common/scope_exit.h
@@ -12,10 +12,17 @@ template <typename Func>
struct ScopeExitHelper {
explicit ScopeExitHelper(Func&& func) : func(std::move(func)) {}
~ScopeExitHelper() {
- func();
+ if (active) {
+ func();
+ }
+ }
+
+ void Cancel() {
+ active = false;
}
Func func;
+ bool active{true};
};
template <typename Func>