core: Move Time::StaticInit call to helper constructor

This commit is contained in:
Gabriel Ferreira
2024-04-09 16:03:02 +02:00
parent 73b33bdf1a
commit a9fb22a442

View File

@@ -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 */