aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2023-08-06 17:49:04 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2023-08-06 18:52:22 +0300
commitd1257d50ffa27ba0ba788a7dd11a797bfbdad0c5 (patch)
treea2542be3d06def7363e3b441e98a46c3625ddb79
parent0febbe057bd1155f09bd3a5205b62a2236739b05 (diff)
downloadydb-d1257d50ffa27ba0ba788a7dd11a797bfbdad0c5.tar.gz
Intermediate changes
-rw-r--r--library/cpp/yt/cpu_clock/benchmark/benchmark.cpp9
-rw-r--r--yt/yt/core/misc/async_slru_cache-inl.h24
-rw-r--r--yt/yt/core/misc/async_slru_cache.h4
3 files changed, 18 insertions, 19 deletions
diff --git a/library/cpp/yt/cpu_clock/benchmark/benchmark.cpp b/library/cpp/yt/cpu_clock/benchmark/benchmark.cpp
index 9d300b6726..86c751a7bb 100644
--- a/library/cpp/yt/cpu_clock/benchmark/benchmark.cpp
+++ b/library/cpp/yt/cpu_clock/benchmark/benchmark.cpp
@@ -26,6 +26,15 @@ void BM_GetCpuApproximateInstant(benchmark::State& state)
BENCHMARK(BM_GetCpuApproximateInstant);
+void BM_GetInstant(benchmark::State& state)
+{
+ for (auto _ : state) {
+ benchmark::DoNotOptimize(GetInstant());
+ }
+}
+
+BENCHMARK(BM_GetInstant);
+
void BM_InstantNow(benchmark::State& state)
{
for (auto _ : state) {
diff --git a/yt/yt/core/misc/async_slru_cache-inl.h b/yt/yt/core/misc/async_slru_cache-inl.h
index 9ed8c1c98b..66b36a830c 100644
--- a/yt/yt/core/misc/async_slru_cache-inl.h
+++ b/yt/yt/core/misc/async_slru_cache-inl.h
@@ -1262,14 +1262,8 @@ void TAsyncSlruCacheBase<TKey, TValue, THash>::NotifyOnTrim(
////////////////////////////////////////////////////////////////////////////////
template <class TKey, class TValue, class THash>
-TAsyncSlruCacheBase<TKey, TValue, THash>::TInsertCookie::TInsertCookie()
- : Active_(false)
-{ }
-
-template <class TKey, class TValue, class THash>
TAsyncSlruCacheBase<TKey, TValue, THash>::TInsertCookie::TInsertCookie(const TKey& key)
: Key_(key)
- , Active_(false)
{ }
template <class TKey, class TValue, class THash>
@@ -1326,23 +1320,17 @@ bool TAsyncSlruCacheBase<TKey, TValue, THash>::TInsertCookie::IsActive() const
template <class TKey, class TValue, class THash>
void TAsyncSlruCacheBase<TKey, TValue, THash>::TInsertCookie::Cancel(const TError& error)
{
- auto expected = true;
- if (!Active_.compare_exchange_strong(expected, false)) {
- return;
+ if (Active_.exchange(false)) {
+ Cache_->CancelInsert(*this, error);
}
-
- Cache_->CancelInsert(*this, error);
}
template <class TKey, class TValue, class THash>
void TAsyncSlruCacheBase<TKey, TValue, THash>::TInsertCookie::EndInsert(TValuePtr value)
{
- auto expected = true;
- if (!Active_.compare_exchange_strong(expected, false)) {
- return;
+ if (Active_.exchange(false)) {
+ Cache_->EndInsert(*this, value);
}
-
- Cache_->EndInsert(*this, value);
}
template <class TKey, class TValue, class THash>
@@ -1360,7 +1348,9 @@ TAsyncSlruCacheBase<TKey, TValue, THash>::TInsertCookie::TInsertCookie(
template <class TKey, class TValue, class THash>
void TAsyncSlruCacheBase<TKey, TValue, THash>::TInsertCookie::Abort()
{
- Cancel(TError(NYT::EErrorCode::Canceled, "Cache item insertion aborted"));
+ if (Active_.load()) {
+ Cancel(TError(NYT::EErrorCode::Canceled, "Cache item insertion aborted"));
+ }
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/yt/yt/core/misc/async_slru_cache.h b/yt/yt/core/misc/async_slru_cache.h
index 501c5e178a..7ddad541f6 100644
--- a/yt/yt/core/misc/async_slru_cache.h
+++ b/yt/yt/core/misc/async_slru_cache.h
@@ -151,7 +151,7 @@ public:
class TInsertCookie
{
public:
- TInsertCookie();
+ TInsertCookie() = default;
explicit TInsertCookie(const TKey& key);
TInsertCookie(TInsertCookie&& other);
TInsertCookie(const TInsertCookie& other) = delete;
@@ -173,7 +173,7 @@ public:
TKey Key_;
TIntrusivePtr<TAsyncSlruCacheBase> Cache_;
TValueFuture ValueFuture_;
- std::atomic<bool> Active_;
+ std::atomic<bool> Active_ = false;
bool InsertedIntoSmallGhost_ = false;
bool InsertedIntoLargeGhost_ = false;