From 8da27cf4b7b05ed45b085557d76cbb0b6dd34cd9 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 19 Jan 2021 09:14:48 +0100 Subject: [PATCH] One more static initialization order fiasco. --- src/mc/mc_base.cpp | 3 ++- src/mc/mc_config.cpp | 9 ++++++--- src/mc/mc_config.hpp | 1 - src/mc/mc_replay.hpp | 11 ++++++++--- src/simix/smx_global.cpp | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index 6b498b61c5..5cc8b4930e 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -8,6 +8,7 @@ #include "src/kernel/activity/CommImpl.hpp" #include "src/kernel/activity/MutexImpl.hpp" #include "src/mc/checker/SimcallInspector.hpp" +#include "src/mc/mc_config.hpp" #include "src/mc/mc_replay.hpp" #include "src/simix/smx_private.hpp" @@ -170,7 +171,7 @@ bool request_is_visible(const s_smx_simcall* req) int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max) { - if (not MC_is_active() && MC_record_path.empty()) { + if (not MC_is_active() && not MC_record_replay_is_active()) { static simgrid::xbt::random::XbtRandom prng; return prng.uniform_int(min, max); } diff --git a/src/mc/mc_config.cpp b/src/mc/mc_config.cpp index b66a228b1e..cfe3511b25 100644 --- a/src/mc/mc_config.cpp +++ b/src/mc/mc_config.cpp @@ -3,6 +3,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "src/mc/mc_config.hpp" #include "src/mc/mc_replay.hpp" #include #if SIMGRID_HAVE_MC @@ -32,11 +33,13 @@ static void _mc_cfg_cb_check(const char* spec, bool more_check = true) /* Replay (this part is enabled even if MC it disabled) */ simgrid::config::Flag _sg_mc_record_path{ - "model-check/replay", "Model-check path to replay (as reported by SimGrid when a violation is reported)", ""}; + "model-check/replay", "Model-check path to replay (as reported by SimGrid when a violation is reported)", "", + [](const std::string& value) { MC_record_path() = value; }}; simgrid::config::Flag _sg_mc_timeout{ - "model-check/timeout", "Whether to enable timeouts for wait requests", false, - [](bool) { _mc_cfg_cb_check("value to enable/disable timeout for wait requests", MC_record_path.empty()); }}; + "model-check/timeout", "Whether to enable timeouts for wait requests", false, [](bool) { + _mc_cfg_cb_check("value to enable/disable timeout for wait requests", not MC_record_replay_is_active()); + }}; #if SIMGRID_HAVE_MC int _sg_do_model_check = 0; diff --git a/src/mc/mc_config.hpp b/src/mc/mc_config.hpp index 93392ef7b1..f249c753e8 100644 --- a/src/mc/mc_config.hpp +++ b/src/mc/mc_config.hpp @@ -11,7 +11,6 @@ /********************************** Configuration of MC **************************************/ extern "C" XBT_PUBLIC int _sg_do_model_check; extern XBT_PUBLIC simgrid::config::Flag _sg_mc_buffering; -extern XBT_PUBLIC simgrid::config::Flag _sg_mc_record_path; extern XBT_PRIVATE simgrid::config::Flag _sg_mc_checkpoint; extern XBT_PUBLIC simgrid::config::Flag _sg_mc_property_file; extern XBT_PUBLIC simgrid::config::Flag _sg_mc_comms_determinism; diff --git a/src/mc/mc_replay.hpp b/src/mc/mc_replay.hpp index 5558e5ada9..4d093624e1 100644 --- a/src/mc/mc_replay.hpp +++ b/src/mc/mc_replay.hpp @@ -6,18 +6,23 @@ #ifndef SIMGRID_MC_REPLAY_H #define SIMGRID_MC_REPLAY_H -#include "src/mc/mc_config.hpp" +#include /** Replay path (if any) in string representation * * This is using the format generated by traceToString(). + * Use a function to avoid static initialization order fiasco. */ -#define MC_record_path (_sg_mc_record_path.get()) +inline std::string& MC_record_path() +{ + static std::string value; + return value; +} /** Whether the replay mode is enabled */ static inline int MC_record_replay_is_active() { - return not MC_record_path.empty(); + return not MC_record_path().empty(); } #endif diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index c03d20bdf3..d0e91ada96 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -412,7 +412,7 @@ static bool SIMIX_execute_timers() void SIMIX_run() { if (MC_record_replay_is_active()) { - simgrid::mc::replay(MC_record_path); + simgrid::mc::replay(MC_record_path()); return; } -- 2.20.1