aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/misc/granup.h
diff options
context:
space:
mode:
authorsingle <single@yandex-team.ru>2022-02-10 16:50:29 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:29 +0300
commit8ae96df130bbede609c3504aa9af1bc6ff5361b3 (patch)
tree4751832974bd75ca721269aa54faa15d76032dfb /library/cpp/messagebus/misc/granup.h
parent5d4e7b7c923852e0f6398791ec98a60cf9faab46 (diff)
downloadydb-8ae96df130bbede609c3504aa9af1bc6ff5361b3.tar.gz
Restoring authorship annotation for <single@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/misc/granup.h')
-rw-r--r--library/cpp/messagebus/misc/granup.h66
1 files changed, 33 insertions, 33 deletions
diff --git a/library/cpp/messagebus/misc/granup.h b/library/cpp/messagebus/misc/granup.h
index 36ecfebc93..8b04aca597 100644
--- a/library/cpp/messagebus/misc/granup.h
+++ b/library/cpp/messagebus/misc/granup.h
@@ -1,50 +1,50 @@
-#pragma once
-
+#pragma once
+
#include <util/datetime/base.h>
#include <util/system/guard.h>
-#include <util/system/mutex.h>
-#include <util/system/spinlock.h>
-
-namespace NBus {
- template <typename TItem, typename TLocker = TSpinLock>
- class TGranUp {
- public:
- TGranUp(TDuration gran)
- : Gran(gran)
+#include <util/system/mutex.h>
+#include <util/system/spinlock.h>
+
+namespace NBus {
+ template <typename TItem, typename TLocker = TSpinLock>
+ class TGranUp {
+ public:
+ TGranUp(TDuration gran)
+ : Gran(gran)
, Next(TInstant::MicroSeconds(0))
{
}
-
+
template <typename TFunctor>
void Update(TFunctor functor, TInstant now, bool force = false) {
if (force || now > Next)
- Set(functor(), now);
- }
-
+ Set(functor(), now);
+ }
+
void Update(const TItem& item, TInstant now, bool force = false) {
if (force || now > Next)
- Set(item, now);
- }
-
+ Set(item, now);
+ }
+
TItem Get() const noexcept {
TGuard<TLocker> guard(Lock);
-
- return Item;
- }
-
- protected:
+
+ return Item;
+ }
+
+ protected:
void Set(const TItem& item, TInstant now) {
TGuard<TLocker> guard(Lock);
-
- Item = item;
-
- Next = now + Gran;
- }
-
- private:
- const TDuration Gran;
+
+ Item = item;
+
+ Next = now + Gran;
+ }
+
+ private:
+ const TDuration Gran;
TLocker Lock;
TItem Item;
TInstant Next;
- };
-}
+ };
+}