From ec45f31ad130e113a31c4f95451a343fe13643db Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 4 May 2019 15:28:20 -0700 Subject: [PATCH] Make debug_level an atomic Fixes a tsan warning --- src/common.cpp | 2 +- src/common.h | 5 +++-- src/fish_tests.cpp | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 73e2f43ae..1ce118608 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -75,7 +75,7 @@ int omitted_newline_width; wchar_t obfuscation_read_char; bool g_profiling_active = false; const wchar_t *program_name; -int debug_level = 1; // default maximum debug output level (errors and warnings) +std::atomic 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 /// Be able to restore the term's foreground process group. diff --git a/src/common.h b/src/common.h index 6b4f33796..bc09cad32 100644 --- a/src/common.h +++ b/src/common.h @@ -12,6 +12,7 @@ #endif #include +#include #include #include #include @@ -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, /// it will not be printed. -extern int debug_level; +extern std::atomic 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, ...) \ do { \ diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index f47e244d7..9cb125fef 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -2426,10 +2426,12 @@ static void test_dup2s() { // Invalid files should fail to open. // Suppress the debug() message. - scoped_push saved_debug_level(&debug_level, -1); + int saved_debug_level = debug_level; + debug_level = -1; chain.push_back(make_shared(2, L"/definitely/not/a/valid/path/for/this/test", 0666)); list = dup2_list_t::resolve_chain(chain); do_test(!list.has_value()); + debug_level = saved_debug_level; } static void test_dup2s_fd_for_target_fd() {