MCPcopy Create free account
hub / github.com/catboost/catboost / SuggestSleepDelay

Function SuggestSleepDelay

library/cpp/yt/threading/spin_wait.cpp:17–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15namespace {
16
17TDuration SuggestSleepDelay(int iteration)
18{
19 static std::atomic<ui64> Rand;
20 auto rand = Rand.load(std::memory_order::relaxed);
21 rand = 0x5deece66dLL * rand + 0xb; // numbers from nrand48()
22 Rand.store(rand, std::memory_order::relaxed);
23
24 constexpr ui64 MinDelayUs = 128;
25
26 // Double delay every 8 iterations, up to 16x (2ms).
27 if (iteration > 32) {
28 iteration = 32;
29 }
30 ui64 delayUs = MinDelayUs << (iteration / 8);
31
32 // Randomize in delay..2*delay range, for resulting 128us..4ms range.
33 delayUs = delayUs | ((delayUs - 1) & rand);
34 return TDuration::MicroSeconds(delayUs);
35}
36
37} // namespace
38

Callers 1

WaitMethod · 0.85

Calls 3

MicroSecondsFunction · 0.85
loadMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected