diff --git a/CMakeLists.txt b/CMakeLists.txt index cb1c485..6713b23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 5.2.34) +set(BLT_VERSION 5.2.35) set(BLT_TARGET BLT) @@ -13,6 +13,7 @@ option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) option(ENABLE_TSAN "Enable the thread data race sanitizer" OFF) option(BLT_DEBUG_OTEL "Enable OpenTelemetry Service" OFF) +option(BLT_LOGGING_THREAD_SAFE "Make sure logging is thread synced" ON) option(BUILD_STD "Build the BLT standard utilities." ON) option(BUILD_PROFILING "Build the BLT profiler extension" ON) @@ -48,6 +49,10 @@ if (BLT_DEBUG_OTEL) # include_directories("${opentelemtry-cpp_INCLUDE_DIRS}") endif () +if (BLT_LOGGING_THREAD_SAFE) + add_compile_definitions(BLT_LOGGING_THREAD_SAFE) +endif () + if(${BLT_DISABLE_STATS}) add_compile_definitions(BLT_DISABLE_STATS) endif () diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap index 154c634..8a889d3 160000 --- a/libraries/parallel-hashmap +++ b/libraries/parallel-hashmap @@ -1 +1 @@ -Subproject commit 154c63489e84d5569d3b466342a2ae8fd99e4734 +Subproject commit 8a889d3699b3c09ade435641fb034427f3fd12b6 diff --git a/src/blt/logging/logging.cpp b/src/blt/logging/logging.cpp index 4bc5cb2..9e0adf7 100644 --- a/src/blt/logging/logging.cpp +++ b/src/blt/logging/logging.cpp @@ -33,6 +33,9 @@ namespace blt::logging }; static global_context_t global_context; +#ifdef BLT_LOGGING_THREAD_SAFE + static std::mutex global_logging_mutex; +#endif struct logging_thread_context_t { @@ -237,6 +240,9 @@ namespace blt::logging void print(std::string str) { +#ifdef BLT_LOGGING_THREAD_SAFE + std::scoped_lock lock{global_logging_mutex}; +#endif const auto& config = get_global_config(); bool should_print = true; if (!config.get_injectors().empty()) @@ -257,6 +263,9 @@ namespace blt::logging void newline() { +#ifdef BLT_LOGGING_THREAD_SAFE + std::scoped_lock lock{global_logging_mutex}; +#endif std::cout << std::endl; }