LLVM 20.0.0git
ExponentialBackoff.cpp
Go to the documentation of this file.
1//===- llvm/Support/ExponentialBackoff.h ------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include <thread>
11
12using namespace llvm;
13
15 auto Now = std::chrono::steady_clock::now();
16 if (Now >= EndTime)
17 return false;
18
19 duration CurMaxWait = std::min(MinWait * CurrentMultiplier, MaxWait);
20 std::uniform_int_distribution<uint64_t> Dist(MinWait.count(),
21 CurMaxWait.count());
22 // Use random_device directly instead of a PRNG as uniform_int_distribution
23 // often only takes a few samples anyway.
24 duration WaitDuration = std::min(duration(Dist(RandDev)), EndTime - Now);
25 if (CurMaxWait < MaxWait)
26 CurrentMultiplier *= 2;
27 std::this_thread::sleep_for(WaitDuration);
28 return true;
29}
bool waitForNextAttempt()
Blocks while waiting for the next attempt.
std::chrono::steady_clock::duration duration
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18