diff --git a/GridKit/Model/PhasorDynamics/Controller/REECB/ReecbImpl.hpp b/GridKit/Model/PhasorDynamics/Controller/REECB/ReecbImpl.hpp index 2ed478014c..5917d14b22 100644 --- a/GridKit/Model/PhasorDynamics/Controller/REECB/ReecbImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Controller/REECB/ReecbImpl.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -1378,8 +1378,8 @@ namespace GridKit /** * @brief Static method to log time constant warnings * - * @note Used in combination with static std:once_flag and std:call_once, - * to reduce the number of times the warning is printed. + * @note Guarded by a static std::atomic flag so the warning is + * printed at most once per model type. */ template void Reecb::logTimeConstantWarning() @@ -1408,9 +1408,11 @@ namespace GridKit if (floor_warning) { - static std::once_flag time_constant_warning_flag_; - std::call_once(time_constant_warning_flag_, - &logTimeConstantWarning); + static std::atomic time_constant_warning_flag_{false}; + if (!time_constant_warning_flag_.exchange(true)) + { + logTimeConstantWarning(); + } } if (PfFlag_ && QFlag_) diff --git a/GridKit/Model/PhasorDynamics/Controller/REPCA/RepcaImpl.hpp b/GridKit/Model/PhasorDynamics/Controller/REPCA/RepcaImpl.hpp index df9da208a3..1e266055db 100644 --- a/GridKit/Model/PhasorDynamics/Controller/REPCA/RepcaImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Controller/REPCA/RepcaImpl.hpp @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #include #include @@ -960,8 +960,8 @@ namespace GridKit /** * @brief Static method to log time constant warnings * - * @note Used in combination with static std:once_flag and std:call_once, - * to reduce the number of times the warning is printed. + * @note Guarded by a static std::atomic flag so the warning is + * printed at most once per model type. */ template void Repca::logTimeConstantWarning() @@ -1000,9 +1000,11 @@ namespace GridKit if (Tfltr_ < TIME_CONSTANT_MINIMUM || Tfv_ < TIME_CONSTANT_MINIMUM || Tp_ < TIME_CONSTANT_MINIMUM || Tlag_ < TIME_CONSTANT_MINIMUM) { - static std::once_flag time_constant_warning_flag_; - std::call_once(time_constant_warning_flag_, - &logTimeConstantWarning); + static std::atomic time_constant_warning_flag_{false}; + if (!time_constant_warning_flag_.exchange(true)) + { + logTimeConstantWarning(); + } } Tfltr_ = std::max(Tfltr_, TIME_CONSTANT_MINIMUM); diff --git a/GridKit/Model/PhasorDynamics/Converter/REGCA/RegcaImpl.hpp b/GridKit/Model/PhasorDynamics/Converter/REGCA/RegcaImpl.hpp index 233a5be867..cf585b6bd0 100644 --- a/GridKit/Model/PhasorDynamics/Converter/REGCA/RegcaImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Converter/REGCA/RegcaImpl.hpp @@ -7,8 +7,8 @@ #pragma once #include +#include #include -#include #include #include @@ -66,8 +66,8 @@ namespace GridKit /** * @brief Static method to log time constant warnings * - * @note Used in combination with static std:once_flag and std:call_once, - * to reduce the number of times the warning is printed. + * @note Guarded by a static std::atomic flag so the warning is + * printed at most once per model type. */ template void Regca::logTimeConstantWarning() @@ -89,9 +89,11 @@ namespace GridKit { if (Tg_ < TIME_CONSTANT_MINIMUM || TM_ < TIME_CONSTANT_MINIMUM) { - static std::once_flag time_constant_warning_flag_; - std::call_once(time_constant_warning_flag_, - &logTimeConstantWarning); + static std::atomic time_constant_warning_flag_{false}; + if (!time_constant_warning_flag_.exchange(true)) + { + logTimeConstantWarning(); + } } Tg_ = std::max(Tg_, TIME_CONSTANT_MINIMUM); diff --git a/GridKit/Model/PhasorDynamics/Exciter/ESDC1A/Esdc1aImpl.hpp b/GridKit/Model/PhasorDynamics/Exciter/ESDC1A/Esdc1aImpl.hpp index a4af51239a..505fc83d7f 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/ESDC1A/Esdc1aImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Exciter/ESDC1A/Esdc1aImpl.hpp @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #include #include @@ -771,8 +771,8 @@ namespace GridKit /** * @brief Static method to log time constant warnings * - * @note Used in combination with static std:once_flag and std:call_once, - * to reduce the number of times the warning is printed. + * @note Guarded by a static std::atomic flag so the warning is + * printed at most once per model type. */ template void Esdc1a::logTimeConstantWarning() @@ -817,9 +817,11 @@ namespace GridKit || Tb_ < TIME_CONSTANT_MINIMUM || Te_ < TIME_CONSTANT_MINIMUM || Tf1_ < TIME_CONSTANT_MINIMUM) { - static std::once_flag time_constant_warning_flag_; - std::call_once(time_constant_warning_flag_, - &logTimeConstantWarning); + static std::atomic time_constant_warning_flag_{false}; + if (!time_constant_warning_flag_.exchange(true)) + { + logTimeConstantWarning(); + } } Tr_ = std::max(Tr_, TIME_CONSTANT_MINIMUM); diff --git a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Impl.hpp b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Impl.hpp index 6be4cf1ebb..0074d0e33b 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Impl.hpp +++ b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Impl.hpp @@ -8,8 +8,8 @@ */ #include +#include #include -#include #include #include @@ -550,8 +550,8 @@ namespace GridKit /** * @brief Static method to log time constant warnings * - * @note Used in combination with static std:once_flag and std:call_once, - * to reduce the number of times the warning is printed. + * @note Guarded by a static std::atomic flag so the warning is + * printed at most once per model type. */ template void Ieeet1::logTimeConstantWarning() @@ -570,9 +570,11 @@ namespace GridKit if (Tr_ < TIME_CONSTANT_MINIMUM || Ta_ < TIME_CONSTANT_MINIMUM || Te_ < TIME_CONSTANT_MINIMUM || Tf_ < TIME_CONSTANT_MINIMUM) { - static std::once_flag time_constant_warning_flag_; - std::call_once(time_constant_warning_flag_, - &logTimeConstantWarning); + static std::atomic time_constant_warning_flag_{false}; + if (!time_constant_warning_flag_.exchange(true)) + { + logTimeConstantWarning(); + } } Tr_ = std::max(Tr_, TIME_CONSTANT_MINIMUM); diff --git a/GridKit/Model/PhasorDynamics/Governor/GASTPTI/GastPtiImpl.hpp b/GridKit/Model/PhasorDynamics/Governor/GASTPTI/GastPtiImpl.hpp index e35cc8a2a1..92aa4f1e0b 100644 --- a/GridKit/Model/PhasorDynamics/Governor/GASTPTI/GastPtiImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Governor/GASTPTI/GastPtiImpl.hpp @@ -7,8 +7,8 @@ #pragma once #include +#include #include -#include #include #include @@ -703,8 +703,8 @@ namespace GridKit /** * @brief Static method to log time constant warnings * - * @note Used in combination with static std:once_flag and std:call_once, - * to reduce the number of times the warning is printed. + * @note Guarded by a static std::atomic flag so the warning is + * printed at most once per model type. */ template void GastPti::logTimeConstantWarning() @@ -735,9 +735,11 @@ namespace GridKit if (floor_warning) { - static std::once_flag time_constant_warning_flag_; - std::call_once(time_constant_warning_flag_, - &logTimeConstantWarning); + static std::atomic time_constant_warning_flag_{false}; + if (!time_constant_warning_flag_.exchange(true)) + { + logTimeConstantWarning(); + } } Vmin_response_ = Vmin_; diff --git a/GridKit/Model/PhasorDynamics/Governor/HYGOV/HygovImpl.hpp b/GridKit/Model/PhasorDynamics/Governor/HYGOV/HygovImpl.hpp index 71ada99e05..1ad51b4240 100644 --- a/GridKit/Model/PhasorDynamics/Governor/HYGOV/HygovImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Governor/HYGOV/HygovImpl.hpp @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #include #include @@ -753,8 +753,8 @@ namespace GridKit /** * @brief Static method to log time constant warnings * - * @note Used in combination with static std:once_flag and std:call_once, - * to reduce the number of times the warning is printed. + * @note Guarded by a static std::atomic flag so the warning is + * printed at most once per model type. */ template void Hygov::logTimeConstantWarning() @@ -816,9 +816,11 @@ namespace GridKit || Tg_ < TIME_CONSTANT_MINIMUM || Tw_ < TIME_CONSTANT_MINIMUM || Tnp_ < TIME_CONSTANT_MINIMUM) { - static std::once_flag time_constant_warning_flag_; - std::call_once(time_constant_warning_flag_, - &logTimeConstantWarning); + static std::atomic time_constant_warning_flag_{false}; + if (!time_constant_warning_flag_.exchange(true)) + { + logTimeConstantWarning(); + } } // HYGOV residuals solve explicitly for the state derivatives to preserve diff --git a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Impl.hpp b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Impl.hpp index 01843aa0fc..a50c3a2748 100644 --- a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Impl.hpp +++ b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Impl.hpp @@ -9,7 +9,7 @@ */ #include -#include +#include #include #include @@ -134,8 +134,8 @@ namespace GridKit /** * @brief Static method to log time constant warnings * - * @note Used in combination with static std:once_flag and std:call_once, - * to reduce the number of times the warning is printed. + * @note Guarded by a static std::atomic flag so the warning is + * printed at most once per model type. */ template void Tgov1::logTimeConstantWarning() @@ -149,9 +149,11 @@ namespace GridKit { if (T1_ < TIME_CONSTANT_MINIMUM || T3_ < TIME_CONSTANT_MINIMUM) { - static std::once_flag time_constant_warning_flag_; - std::call_once(time_constant_warning_flag_, - &logTimeConstantWarning); + static std::atomic time_constant_warning_flag_{false}; + if (!time_constant_warning_flag_.exchange(true)) + { + logTimeConstantWarning(); + } } T1_ = std::max(T1_, TIME_CONSTANT_MINIMUM);