aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkvk1920 <kvk1920@yandex-team.com>2024-09-25 16:35:16 +0300
committerkvk1920 <kvk1920@yandex-team.com>2024-09-25 16:51:33 +0300
commit07ceeeab0c1d69f642190a110ca748163bc189b6 (patch)
treeaa409602607cb8c1cec49b6deba1e33d495f5ea9
parent8ae794f5031c0acd533e9b9ba70c5e063cf0f63b (diff)
downloadydb-07ceeeab0c1d69f642190a110ca748163bc189b6.tar.gz
Introduce persistent state transient cache
commit_hash:1f6b2d6feec63b886995543a1656e6e44da18366
-rw-r--r--yt/yt/core/misc/atomic_object-inl.h10
-rw-r--r--yt/yt/core/misc/atomic_object.h8
2 files changed, 16 insertions, 2 deletions
diff --git a/yt/yt/core/misc/atomic_object-inl.h b/yt/yt/core/misc/atomic_object-inl.h
index f75722cb32..1e76cbf5ab 100644
--- a/yt/yt/core/misc/atomic_object-inl.h
+++ b/yt/yt/core/misc/atomic_object-inl.h
@@ -54,7 +54,7 @@ bool TAtomicObject<T>::CompareExchange(T& expected, const T& desired)
}
template <class T>
-template <class F>
+template <CInvocable<void(T&)> F>
void TAtomicObject<T>::Transform(const F& func)
{
auto guard = WriterGuard(Spinlock_);
@@ -62,6 +62,14 @@ void TAtomicObject<T>::Transform(const F& func)
}
template <class T>
+template <class R, CInvocable<R(const T&)> F>
+R TAtomicObject<T>::Read(const F& func) const
+{
+ auto guard = ReaderGuard(Spinlock_);
+ return func(Object_);
+}
+
+template <class T>
T TAtomicObject<T>::Load() const
{
auto guard = ReaderGuard(Spinlock_);
diff --git a/yt/yt/core/misc/atomic_object.h b/yt/yt/core/misc/atomic_object.h
index d75e9cfd7d..91ef9278b0 100644
--- a/yt/yt/core/misc/atomic_object.h
+++ b/yt/yt/core/misc/atomic_object.h
@@ -2,6 +2,8 @@
#include <library/cpp/yt/threading/rw_spin_lock.h>
+#include <library/cpp/yt/misc/concepts.h>
+
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
@@ -30,9 +32,13 @@ public:
bool CompareExchange(T& expected, const T& desired);
//! Atomically transforms the value with function #func.
- template <class F>
+ template <CInvocable<void(T&)> F>
void Transform(const F& func);
+ //! Atomicaly reads the value with function #func.
+ template <class R = void, CInvocable<R(const T&)> F>
+ R Read(const F& func) const;
+
T Load() const;
private: