diff options
author | abogutskiy <abogutskiy@yandex-team.ru> | 2022-02-10 16:50:05 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:05 +0300 |
commit | 78454ca6aab96463952682e635688185282ccdcd (patch) | |
tree | 17159d279d7f9d6d10d91ec91b61827342a85540 /library/cpp/actors | |
parent | cf94099c3ea704df29c11dfb77e2adec41a6708d (diff) | |
download | ydb-78454ca6aab96463952682e635688185282ccdcd.tar.gz |
Restoring authorship annotation for <abogutskiy@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/actors')
-rw-r--r-- | library/cpp/actors/dnscachelib/timekeeper.h | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/library/cpp/actors/dnscachelib/timekeeper.h b/library/cpp/actors/dnscachelib/timekeeper.h index 0528d8549c..4c4602f083 100644 --- a/library/cpp/actors/dnscachelib/timekeeper.h +++ b/library/cpp/actors/dnscachelib/timekeeper.h @@ -1,8 +1,8 @@ #pragma once -#include <util/datetime/base.h> +#include <util/datetime/base.h> #include <util/generic/singleton.h> -#include <util/string/cast.h> +#include <util/string/cast.h> #include <util/system/thread.h> #include <util/system/event.h> #include <util/system/env.h> @@ -13,10 +13,10 @@ class TTimeKeeper { public: - static TInstant GetNow(void) { + static TInstant GetNow(void) { return TInstant::MicroSeconds(GetTime()); - } - + } + static time_t GetTime(void) { return Singleton<TTimeKeeper>()->CurrentTime.tv_sec; } @@ -27,41 +27,41 @@ public: TTimeKeeper() : Thread(&TTimeKeeper::Worker, this) - { + { ConstTime = !!GetEnv("TEST_TIME"); - if (ConstTime) { - try { + if (ConstTime) { + try { CurrentTime.tv_sec = FromString<ui32>(GetEnv("TEST_TIME")); - } catch (TFromStringException exc) { - ConstTime = false; - } - } - if (!ConstTime) { + } catch (TFromStringException exc) { + ConstTime = false; + } + } + if (!ConstTime) { gettimeofday(&CurrentTime, nullptr); - Thread.Start(); - } + Thread.Start(); + } } ~TTimeKeeper() { - if (!ConstTime) { - Exit.Signal(); - Thread.Join(); - } + if (!ConstTime) { + Exit.Signal(); + Thread.Join(); + } } private: static const ui32 UpdateInterval = 100000; struct timeval CurrentTime; - bool ConstTime; + bool ConstTime; TSystemEvent Exit; TThread Thread; static void* Worker(void* arg) { TTimeKeeper* owner = static_cast<TTimeKeeper*>(arg); - + do { /* Race condition may occur here but locking looks too expensive */ - + gettimeofday(&owner->CurrentTime, nullptr); } while (!owner->Exit.WaitT(TDuration::MicroSeconds(UpdateInterval))); |