diff options
author | serg-belyakov <[email protected]> | 2025-08-01 13:55:06 +0300 |
---|---|---|
committer | serg-belyakov <[email protected]> | 2025-08-01 14:28:05 +0300 |
commit | 8ff713d56badf1e7f59916a9850028245a20cc3c (patch) | |
tree | 1177d19a628f5b3dd5b148b6875651ac8a4f6c88 /library/cpp | |
parent | 3b47f6e69ae8534f4595086c40faf14fb3a2661a (diff) |
Read atomics properly in TBucketQuoter, KIKIMR-23623
Read atomics properly
commit_hash:d14844a3e23df856c1ba3d2daec067918fe64ef3
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/bucket_quoter/bucket_quoter.h | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/library/cpp/bucket_quoter/bucket_quoter.h b/library/cpp/bucket_quoter/bucket_quoter.h index ce2d96b65d8..eda294d88b0 100644 --- a/library/cpp/bucket_quoter/bucket_quoter.h +++ b/library/cpp/bucket_quoter/bucket_quoter.h @@ -198,7 +198,7 @@ public: return 0; } - ui32 usec = (-Bucket * 1000000) / (*InflowTokensPerSecond); + ui32 usec = (-Bucket * 1000000) / AtomicGet(*InflowTokensPerSecond); return usec; } @@ -211,7 +211,7 @@ public: if (Bucket >= 0) { return 0; } - ui32 usec = (-Bucket * 1000000) / (*InflowTokensPerSecond); + ui32 usec = (-Bucket * 1000000) / AtomicGet(*InflowTokensPerSecond); return usec; } @@ -232,14 +232,16 @@ private: TTime now = Timer::Now(); ui64 elapsed = Timer::Duration(LastAdd, now); - if (*InflowTokensPerSecond * elapsed >= Timer::Resolution) { - ui64 inflow = *InflowTokensPerSecond * elapsed / Timer::Resolution; + ui64 delta = AtomicGet(*InflowTokensPerSecond) * elapsed; + if (delta >= Timer::Resolution) { + ui64 inflow = delta / Timer::Resolution; if (AggregateInflow) { *AggregateInflow += inflow; } Bucket += inflow; - if (Bucket > *BucketTokensCapacity) { - Bucket = *BucketTokensCapacity; + i64 capacity = AtomicGet(*BucketTokensCapacity); + if (Bucket > capacity) { + Bucket = capacity; } LastAdd = now; @@ -260,8 +262,9 @@ private: void AddNoLock(ui64 tokens) { Bucket += tokens; - if (Bucket > *BucketTokensCapacity) { - Bucket = *BucketTokensCapacity; + i64 capacity = AtomicGet(*BucketTokensCapacity); + if (Bucket > capacity) { + Bucket = capacity; } } |