Make debug_level an atomic

Fixes a tsan warning
This commit is contained in:
ridiculousfish 2019-05-04 15:28:20 -07:00
parent 0dd9f64bd9
commit ec45f31ad1
3 changed files with 7 additions and 4 deletions

View file

@ -75,7 +75,7 @@ int omitted_newline_width;
wchar_t obfuscation_read_char; wchar_t obfuscation_read_char;
bool g_profiling_active = false; bool g_profiling_active = false;
const wchar_t *program_name; const wchar_t *program_name;
int debug_level = 1; // default maximum debug output level (errors and warnings) std::atomic<int> debug_level{1}; // default maximum debug output level (errors and warnings)
int debug_stack_frames = 0; // default number of stack frames to show on debug() calls int debug_stack_frames = 0; // default number of stack frames to show on debug() calls
/// Be able to restore the term's foreground process group. /// Be able to restore the term's foreground process group.

View file

@ -12,6 +12,7 @@
#endif #endif
#include <algorithm> #include <algorithm>
#include <atomic>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
@ -158,9 +159,9 @@ typedef unsigned int escape_flags_t;
/// The verbosity level of fish. If a call to debug has a severity level higher than \c debug_level, /// The verbosity level of fish. If a call to debug has a severity level higher than \c debug_level,
/// it will not be printed. /// it will not be printed.
extern int debug_level; extern std::atomic<int> debug_level;
inline bool should_debug(int level) { return level <= debug_level; } inline bool should_debug(int level) { return level <= debug_level.load(std::memory_order_relaxed); }
#define debug(level, ...) \ #define debug(level, ...) \
do { \ do { \

View file

@ -2426,10 +2426,12 @@ static void test_dup2s() {
// Invalid files should fail to open. // Invalid files should fail to open.
// Suppress the debug() message. // Suppress the debug() message.
scoped_push<int> saved_debug_level(&debug_level, -1); int saved_debug_level = debug_level;
debug_level = -1;
chain.push_back(make_shared<io_file_t>(2, L"/definitely/not/a/valid/path/for/this/test", 0666)); chain.push_back(make_shared<io_file_t>(2, L"/definitely/not/a/valid/path/for/this/test", 0666));
list = dup2_list_t::resolve_chain(chain); list = dup2_list_t::resolve_chain(chain);
do_test(!list.has_value()); do_test(!list.has_value());
debug_level = saved_debug_level;
} }
static void test_dup2s_fd_for_target_fd() { static void test_dup2s_fd_for_target_fd() {