diff options
author | heios <heios@yandex-team.ru> | 2022-02-10 16:50:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:15 +0300 |
commit | 58861ee1428f6e29c13edd982e662c38dd44c105 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/cache/thread_safe_cache.h | |
parent | e0ff5d1ed8ec4db4bba3153fc3c3acb85052ada9 (diff) | |
download | ydb-58861ee1428f6e29c13edd982e662c38dd44c105.tar.gz |
Restoring authorship annotation for <heios@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/cache/thread_safe_cache.h')
-rw-r--r-- | library/cpp/cache/thread_safe_cache.h | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/library/cpp/cache/thread_safe_cache.h b/library/cpp/cache/thread_safe_cache.h index 6c3305af2e..71e1442717 100644 --- a/library/cpp/cache/thread_safe_cache.h +++ b/library/cpp/cache/thread_safe_cache.h @@ -6,13 +6,13 @@ #include <util/system/rwlock.h> namespace NPrivate { - // We are interested in getters promotion policy _here_ because of Read-Write-Lock optimizations. - enum class EGettersPromotionPolicy { - Promoted, // LRU, TLRU, MRU, etc. - Unpromoted // FIFO, LIFO, LW, etc. - }; - - template <class Key, class Value, template <class, class> class List, EGettersPromotionPolicy GettersPromotionPolicy, class... TArgs> + // We are interested in getters promotion policy _here_ because of Read-Write-Lock optimizations. + enum class EGettersPromotionPolicy { + Promoted, // LRU, TLRU, MRU, etc. + Unpromoted // FIFO, LIFO, LW, etc. + }; + + template <class Key, class Value, template <class, class> class List, EGettersPromotionPolicy GettersPromotionPolicy, class... TArgs> class TThreadSafeCache { public: using TPtr = TAtomicSharedPtr<Value>; @@ -21,7 +21,7 @@ namespace NPrivate { public: using TKey = Key; using TValue = Value; - using TOwner = TThreadSafeCache<Key, Value, List, GettersPromotionPolicy, TArgs...>; + using TOwner = TThreadSafeCache<Key, Value, List, GettersPromotionPolicy, TArgs...>; public: virtual ~ICallbacks() = default; @@ -96,30 +96,30 @@ namespace NPrivate { return TThreadSafeCacheSingleton<TCallbacks>::Clear(); } - size_t GetMaxSize() const { - TReadGuard w(Mutex); - return Cache.GetMaxSize(); - } - - void SetMaxSize(size_t newSize) { - TWriteGuard w(Mutex); - Cache.SetMaxSize(newSize); - } - + size_t GetMaxSize() const { + TReadGuard w(Mutex); + return Cache.GetMaxSize(); + } + + void SetMaxSize(size_t newSize) { + TWriteGuard w(Mutex); + Cache.SetMaxSize(newSize); + } + private: template <bool AllowNullValues> const TPtr GetValue(TArgs... args) const { Key key = Callbacks.GetKey(args...); - switch (GettersPromotionPolicy) { - case EGettersPromotionPolicy::Promoted: - break; - case EGettersPromotionPolicy::Unpromoted: { - TReadGuard r(Mutex); - typename TInternalCache::TIterator i = Cache.FindWithoutPromote(key); - if (i != Cache.End()) { - return i.Value(); - } - break; + switch (GettersPromotionPolicy) { + case EGettersPromotionPolicy::Promoted: + break; + case EGettersPromotionPolicy::Unpromoted: { + TReadGuard r(Mutex); + typename TInternalCache::TIterator i = Cache.FindWithoutPromote(key); + if (i != Cache.End()) { + return i.Value(); + } + break; } } TWriteGuard w(Mutex); @@ -180,22 +180,22 @@ namespace NPrivate { using TListType = TLWList<TKey, TValue, int, TConstWeighter<TValue>>; template <class TKey, class TValue, class... TArgs> - using TCache = TThreadSafeCache<TKey, TValue, TListType, EGettersPromotionPolicy::Unpromoted, TArgs...>; + using TCache = TThreadSafeCache<TKey, TValue, TListType, EGettersPromotionPolicy::Unpromoted, TArgs...>; + }; + + struct TLRUHelper { + template <class TKey, class TValue> + using TListType = TLRUList<TKey, TValue>; + + template <class TKey, class TValue, class... TArgs> + using TCache = TThreadSafeCache<TKey, TValue, TListType, EGettersPromotionPolicy::Promoted, TArgs...>; }; - struct TLRUHelper { - template <class TKey, class TValue> - using TListType = TLRUList<TKey, TValue>; - - template <class TKey, class TValue, class... TArgs> - using TCache = TThreadSafeCache<TKey, TValue, TListType, EGettersPromotionPolicy::Promoted, TArgs...>; - }; - } template <class TKey, class TValue, class... TArgs> using TThreadSafeCache = typename NPrivate::TLWHelper::template TCache<TKey, TValue, TArgs...>; - -template <class TKey, class TValue, class... TArgs> -using TThreadSafeLRUCache = typename NPrivate::TLRUHelper::template TCache<TKey, TValue, TArgs...>; - + +template <class TKey, class TValue, class... TArgs> +using TThreadSafeLRUCache = typename NPrivate::TLRUHelper::template TCache<TKey, TValue, TArgs...>; + |