diff options
author | lukyan <lukyan@yandex-team.com> | 2023-12-05 19:07:41 +0300 |
---|---|---|
committer | lukyan <lukyan@yandex-team.com> | 2023-12-05 20:50:57 +0300 |
commit | d5b84ed65f77eab0135b9d0ee025556f4507b62b (patch) | |
tree | 5c5db90ad950923a5554c4a0f5fac239b3f44c53 /library/cpp/yt/cpu_clock | |
parent | ddadddf4718f23838ed4ffb8e6aa1f126301cf55 (diff) | |
download | ydb-d5b84ed65f77eab0135b9d0ee025556f4507b62b.tar.gz |
Use volatile TLS in library/cpp/yt
Diffstat (limited to 'library/cpp/yt/cpu_clock')
-rw-r--r-- | library/cpp/yt/cpu_clock/clock.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/library/cpp/yt/cpu_clock/clock.cpp b/library/cpp/yt/cpu_clock/clock.cpp index eda3f03bbc..0ed65e3b92 100644 --- a/library/cpp/yt/cpu_clock/clock.cpp +++ b/library/cpp/yt/cpu_clock/clock.cpp @@ -4,6 +4,8 @@ #include <library/cpp/yt/assert/assert.h> +#include <library/cpp/yt/misc/tls.h> + namespace NYT { //////////////////////////////////////////////////////////////////////////////// @@ -31,14 +33,16 @@ double GetTicksToMicroseconds() TCalibrationState GetCalibrationState(TCpuInstant cpuInstant) { - thread_local TCalibrationState State; + YT_THREAD_LOCAL(TCalibrationState) State; + + auto& state = GetTlsRef(State); - if (State.CpuInstant + CalibrationCpuPeriod < cpuInstant) { - State.CpuInstant = cpuInstant; - State.Instant = TInstant::Now(); + if (state.CpuInstant + CalibrationCpuPeriod < cpuInstant) { + state.CpuInstant = cpuInstant; + state.Instant = TInstant::Now(); } - return State; + return state; } TCalibrationState GetCalibrationState() |