@@ -163,10 +163,12 @@ class System {
163
163
// Close mem and plugins
164
164
virtual void close () = 0;
165
165
virtual void purgeAllEvents () = 0;
166
- bool running () { return m_running; }
166
+ bool running () {
167
+ std::atomic_signal_fence (std::memory_order_relaxed);
168
+ return m_running && !m_quitting;
169
+ }
167
170
const bool *runningPtr () { return &m_running; }
168
171
bool quitting () { return m_quitting; }
169
- bool terminating () { return m_terminating; }
170
172
int exitCode () { return m_exitCode; }
171
173
bool emergencyExit () { return m_emergencyExit; }
172
174
[[gnu::cold]] void pause (bool exception = false ) {
@@ -175,22 +177,15 @@ class System {
175
177
m_eventBus->signal (Events::ExecutionFlow::Pause{exception});
176
178
}
177
179
void resume () {
178
- if (m_running || m_terminating ) return ;
180
+ if (m_running) return ;
179
181
m_running = true ;
180
182
m_eventBus->signal (Events::ExecutionFlow::Run{});
181
183
}
182
184
virtual void testQuit (int code) = 0;
183
- [[gnu::cold]] void terminateSignalSafe () {
184
- // about the only thing signal handlers can do safely is switch a flag
185
- m_terminating = true ;
186
- m_running = false ;
187
- }
185
+ // This needs to only mutate variables, as it requires to be signal-safe.
188
186
[[gnu::cold]] void quit (int code = 0 ) {
189
187
m_quitting = true ;
190
- pause ();
191
188
m_exitCode = code;
192
- m_eventBus->signal (Events::Quitting{});
193
- purgeAllEvents ();
194
189
}
195
190
196
191
std::shared_ptr<EventBus::EventBus> m_eventBus = std::make_shared<EventBus::EventBus>();
@@ -263,9 +258,18 @@ class System {
263
258
std::map<uint64_t , std::string> m_i18n;
264
259
std::map<std::string, decltype (m_i18n)> m_locales;
265
260
std::string m_currentLocale;
261
+ // If true, indicates that the emulator is currently capturing the main loop
262
+ // and actively emulates the PSX hardware. If false, the emulator is paused,
263
+ // waiting for user input or other events inside the UI. The way the UI
264
+ // is refreshed is by calling update() periodically, so this boolean affects
265
+ // the moment when and how update() is called.
266
266
bool m_running = false ;
267
+ // If true, indicates that the emulator is quitting. This can be set by a
268
+ // number of events, including the user pressing the quit button or the
269
+ // emulator itself requesting a quit due to testing for instance. This will
270
+ // cause the two main loop to exit: the inner one being the emulator itself,
271
+ // and the outer one being the main.cc loop.
267
272
bool m_quitting = false ;
268
- bool m_terminating = false ;
269
273
int m_exitCode = 0 ;
270
274
struct LocaleInfo {
271
275
const std::string filename;
0 commit comments