clang-tools  14.0.0git
Public Member Functions | List of all members
clang::clangd::PeriodicThrottler Class Reference

Used to guard an operation that should run at most every N seconds. More...

#include <Threading.h>

Public Member Functions

 PeriodicThrottler (Stopwatch::duration Period, Stopwatch::duration Delay={})
 If Period is zero, the throttler will return true every time. More...
 
bool operator() ()
 Returns whether the operation should run at this time. More...
 

Detailed Description

Used to guard an operation that should run at most every N seconds.

Usage: mutable PeriodicThrottler ShouldLog(std::chrono::seconds(1)); void calledFrequently() { if (ShouldLog()) log("this is not spammy"); }

This class is threadsafe. If multiple threads are involved, then the guarded operation still needs to be threadsafe!

Definition at line 184 of file Threading.h.

Constructor & Destructor Documentation

◆ PeriodicThrottler()

clang::clangd::PeriodicThrottler::PeriodicThrottler ( Stopwatch::duration  Period,
Stopwatch::duration  Delay = {} 
)
inline

If Period is zero, the throttler will return true every time.

Definition at line 193 of file Threading.h.

Member Function Documentation

◆ operator()()

bool clang::clangd::PeriodicThrottler::operator() ( )

Returns whether the operation should run at this time.

operator() is safe to call concurrently.

Definition at line 122 of file Threading.cpp.


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