X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8c6bbb14f44b8daed5ea43d80880c6bf2155118b..bfe580c9acb43ca1ca658f9111d4cd6f5951bbdc:/src/xbt/log.cpp diff --git a/src/xbt/log.cpp b/src/xbt/log.cpp index e9c6542863..d21ea0e07b 100644 --- a/src/xbt/log.cpp +++ b/src/xbt/log.cpp @@ -6,7 +6,6 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/xbt/log_private.hpp" -#include "src/xbt/xbt_modinter.h" #include "xbt/string.hpp" #include "xbt/sysdep.h" @@ -56,6 +55,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log, xbt, "Loggings from the logging mechanism i static void xbt_log_help(); static void xbt_log_help_categories(); +static void xbt_log_postexit(); void xbt_log_init(int *argc, char **argv) { @@ -64,6 +64,7 @@ void xbt_log_init(int *argc, char **argv) int parse_args = 1; // Stop parsing the parameters once we found '--' xbt_log_control_set("xbt_help.app:stdout xbt_help.threshold:VERBOSE xbt_help.fmt:%m%n"); + atexit(xbt_log_postexit); /* Set logs and init log submodule */ for (int i = 1; i < *argc; i++) { @@ -97,24 +98,27 @@ void xbt_log_init(int *argc, char **argv) } } -static void log_cat_exit(const s_xbt_log_category_t* cat) +static void log_cat_exit(xbt_log_category_t cat) { if (cat->appender) { if (cat->appender->free_) cat->appender->free_(cat->appender); xbt_free(cat->appender); + cat->appender = nullptr; } if (cat->layout) { if (cat->layout->free_) cat->layout->free_(cat->layout); xbt_free(cat->layout); + cat->layout = nullptr; } - for (auto const* child = cat->firstChild; child != nullptr; child = child->nextSibling) + for (auto* child = cat->firstChild; child != nullptr; child = child->nextSibling) log_cat_exit(child); + cat->firstChild = nullptr; } -void xbt_log_postexit(void) +static void xbt_log_postexit(void) { XBT_VERB("Exiting log"); log_cat_exit(&_XBT_LOGV(XBT_LOG_ROOT_CAT)); @@ -231,7 +235,7 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority return priority >= category->threshold; static std::recursive_mutex log_cat_init_mutex; - log_cat_init_mutex.lock(); + const std::scoped_lock lock(log_cat_init_mutex); XBT_DEBUG("Initializing category '%s' (firstChild=%s, nextSibling=%s)", category->name, (category->firstChild ? category->firstChild->name : "none"), @@ -275,7 +279,6 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority } category->initialized = 1; - log_cat_init_mutex.unlock(); return priority >= category->threshold; }