LLVM 22.0.0git
llvm::ExponentialBackoff Class Reference

A class to help implement exponential backoff. More...

#include "llvm/Support/ExponentialBackoff.h"

Public Types

using duration = std::chrono::steady_clock::duration
using time_point = std::chrono::steady_clock::time_point

Public Member Functions

 ExponentialBackoff (duration Timeout, duration MinWait=std::chrono::milliseconds(10), duration MaxWait=std::chrono::milliseconds(500))
LLVM_ABI bool waitForNextAttempt ()
 Blocks while waiting for the next attempt.

Detailed Description

A class to help implement exponential backoff.

Example usage:

ExponentialBackoff Backoff(10s);
do {
if (tryToDoSomething())
return ItWorked;
} while (Backoff.waitForNextAttempt());
return Timeout;
ExponentialBackoff(duration Timeout, duration MinWait=std::chrono::milliseconds(10), duration MaxWait=std::chrono::milliseconds(500))
@ Timeout
Reached timeout while waiting for the owner to release the lock.

Definition at line 34 of file ExponentialBackoff.h.

Member Typedef Documentation

◆ duration

using llvm::ExponentialBackoff::duration = std::chrono::steady_clock::duration

Definition at line 36 of file ExponentialBackoff.h.

◆ time_point

using llvm::ExponentialBackoff::time_point = std::chrono::steady_clock::time_point

Definition at line 37 of file ExponentialBackoff.h.

Constructor & Destructor Documentation

◆ ExponentialBackoff()

llvm::ExponentialBackoff::ExponentialBackoff ( duration Timeout,
duration MinWait = std::chrono::milliseconds(10),
duration MaxWait = std::chrono::milliseconds(500) )
inline
Parameters
Timeoutthe maximum wall time this should run for starting when this object is constructed.
MinWaitthe minimum amount of time waitForNextAttempt will sleep for.
MaxWaitthe maximum amount of time waitForNextAttempt will sleep for.

Definition at line 45 of file ExponentialBackoff.h.

References now(), and llvm::Timeout.

Member Function Documentation

◆ waitForNextAttempt()

bool ExponentialBackoff::waitForNextAttempt ( )

Blocks while waiting for the next attempt.

Returns
true if you should try again, false if the timeout has been reached.

Definition at line 14 of file ExponentialBackoff.cpp.

Referenced by llvm::LockFileManager::waitForUnlockFor().


The documentation for this class was generated from the following files: