diff options
| author | single <[email protected]> | 2022-02-10 16:50:29 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:50:29 +0300 | 
| commit | 8ae96df130bbede609c3504aa9af1bc6ff5361b3 (patch) | |
| tree | 4751832974bd75ca721269aa54faa15d76032dfb /library/cpp/messagebus/misc/granup.h | |
| parent | 5d4e7b7c923852e0f6398791ec98a60cf9faab46 (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/misc/granup.h')
| -rw-r--r-- | library/cpp/messagebus/misc/granup.h | 66 | 
1 files changed, 33 insertions, 33 deletions
diff --git a/library/cpp/messagebus/misc/granup.h b/library/cpp/messagebus/misc/granup.h index 36ecfebc93a..8b04aca5978 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; -    }; -} +    };  +}   | 
