aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/unified_agent_client/clock.cpp
diff options
context:
space:
mode:
authorhor911 <hor911@ydb.tech>2023-02-09 12:40:11 +0300
committerhor911 <hor911@ydb.tech>2023-02-09 12:40:11 +0300
commit24689527cd888aa8a640ecb5077e656b3520d373 (patch)
treea613ff4cd9567b7113e8376a17f8b85897a42790 /library/cpp/unified_agent_client/clock.cpp
parent8642d3642932f03663ba7d2d9670707c192207fd (diff)
downloadydb-24689527cd888aa8a640ecb5077e656b3520d373.tar.gz
Log backend move
Diffstat (limited to 'library/cpp/unified_agent_client/clock.cpp')
-rw-r--r--library/cpp/unified_agent_client/clock.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/library/cpp/unified_agent_client/clock.cpp b/library/cpp/unified_agent_client/clock.cpp
new file mode 100644
index 0000000000..192c998a02
--- /dev/null
+++ b/library/cpp/unified_agent_client/clock.cpp
@@ -0,0 +1,48 @@
+#include "clock.h"
+
+namespace NUnifiedAgent {
+ void TClock::Configure() {
+ Y_VERIFY(!Configured_);
+
+ Configured_ = true;
+ }
+
+ void TClock::SetBase(TInstant value) {
+ Y_VERIFY(Configured_);
+
+ Base_.store(value.GetValue());
+ }
+
+ void TClock::ResetBase() {
+ Base_.store(0);
+ }
+
+ void TClock::ResetBaseWithShift() {
+ Y_VERIFY(Configured_);
+
+ Shift_.store(static_cast<i64>(Base_.exchange(0)) - static_cast<i64>(::Now().GetValue()));
+ }
+
+ void TClock::SetShift(TDuration value) {
+ Y_VERIFY(Configured_);
+
+ Shift_.fetch_add(value.GetValue());
+ }
+
+ void TClock::ResetShift() {
+ Shift_.store(0);
+ }
+
+ TInstant TClock::Get() {
+ auto base = Base_.load();
+ if (base == 0) {
+ base = ::Now().GetValue();
+ }
+ base += Shift_.load();
+ return TInstant::FromValue(base);
+ }
+
+ bool TClock::Configured_{false};
+ std::atomic<ui64> TClock::Base_{0};
+ std::atomic<i64> TClock::Shift_{0};
+}