Skip to content

Commit 8fbaedf

Browse files
committed
Use atomic bool for shutdown flag
1 parent cf28bd3 commit 8fbaedf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/Crashlog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CrashInfo crash_info;
2020

2121
std::atomic<bool> crashed = false;
2222
std::atomic<bool> crashlog_ready = false;
23+
std::atomic<bool> shutdown = false;
2324

2425
// Use eventfd for async-signal safe waiting
2526
int crashlog_complete = -1;
@@ -40,10 +41,9 @@ void signal_crashlog_complete() {
4041
}
4142

4243
std::thread crashlog_thread;
43-
volatile bool shutdown = false;
4444

4545
extern "C" void dfhack_crashlog_handle_signal(int sig) {
46-
if (shutdown || crashed.exchange(true) || crashlog_ready.load()) {
46+
if (shutdown.load() || crashed.exchange(true) || crashlog_ready.load()) {
4747
// Ensure the signal handler doesn't try to write a crashlog
4848
// whilst the crashlog thread is unavailable.
4949
std::quick_exit(1);
@@ -133,7 +133,7 @@ void dfhack_save_crashlog() {
133133
void dfhack_crashlog_thread() {
134134
// Wait for activation signal
135135
flag_wait(crashlog_ready);
136-
if (shutdown) // Shutting down gracefully, end thread.
136+
if (shutdown.load()) // Shutting down gracefully, end thread.
137137
return;
138138

139139
dfhack_save_crashlog();
@@ -163,7 +163,7 @@ namespace DFHack {
163163
}
164164

165165
void dfhack_crashlog_shutdown() {
166-
shutdown = true;
166+
shutdown.exchange(true);
167167
for (int signal : desired_signals) {
168168
std::signal(signal, SIG_DFL);
169169
}

0 commit comments

Comments
 (0)