From a9fb22a442d4efaf9eba6afa200e0c90bca14a8a Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Tue, 9 Apr 2024 16:03:02 +0200 Subject: [PATCH] core: Move Time::StaticInit call to helper constructor --- src/core/model/nstime.h | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/core/model/nstime.h b/src/core/model/nstime.h index a90ebd295..f73c47190 100644 --- a/src/core/model/nstime.h +++ b/src/core/model/nstime.h @@ -840,13 +840,6 @@ typedef void (*Time)(Time oldValue, Time newValue); } // namespace TracedValueCallback -/** - * Force static initialization order of Time in each compilation unit. - * This is internal to the Time implementation. - * \relates Time - */ -static bool g_TimeStaticInit [[maybe_unused]] = Time::StaticInit(); - /** * Equality operator for Time. * \param [in] lhs The first value @@ -1490,6 +1483,27 @@ class TimeWithUnit */ TYPENAMEGET_DEFINE(Time); +/** + * \ingroup time + * + * \brief Helper class to force static initialization + * of Time in each compilation unit, ensuring it is + * initialized before usage. + * This is internal to the Time implementation. + * \relates Time + */ +class TimeInitializationHelper +{ + public: + /** Default constructor calls Time::StaticInit */ + TimeInitializationHelper() + { + Time::StaticInit(); + } +}; + +static TimeInitializationHelper g_timeInitHelper; ///< Instance of Time static initialization helper + } // namespace ns3 #endif /* TIME_H */