23 #include <condition_variable> 26 #include <unordered_map> 86 : isPoisson(poisson), poissonMean(mean) {}
102 std::chrono::milliseconds interval,
104 std::chrono::milliseconds startDelay = std::chrono::milliseconds(0));
112 std::chrono::milliseconds interval,
115 std::chrono::milliseconds startDelay = std::chrono::milliseconds(0));
123 std::chrono::milliseconds startDelay = std::chrono::milliseconds(0));
132 std::chrono::milliseconds minInterval,
133 std::chrono::milliseconds maxInterval,
135 std::chrono::milliseconds startDelay);
146 std::chrono::milliseconds interval,
148 std::chrono::milliseconds startDelay = std::chrono::milliseconds(0));
160 std::chrono::steady_clock::time_point,
161 std::chrono::steady_clock::time_point)>;
177 std::chrono::milliseconds startDelay);
189 std::chrono::milliseconds startDelay);
251 std::chrono::milliseconds delay,
255 getNextRunTimeFunc(
std::
move(intervalFn)),
257 intervalDistDescription,
266 std::chrono::milliseconds delay,
269 nextRunTimeFunc(
std::
move(nextRunTimeFn)),
273 intervalDescr(intervalDistDescription),
278 return [intervalFn =
std::move(intervalFn)](
279 std::chrono::steady_clock::time_point ,
280 std::chrono::steady_clock::time_point curTime)
mutable {
281 return curTime + intervalFn();
289 nextRunTime = nextRunTimeFunc(nextRunTime, curTime);
292 nextRunTime = nextRunTimeFunc(nextRunTime, nextRunTime);
295 nextRunTime = curTime + startDelay;
308 const std::unique_ptr<RepeatFunc>& f1,
309 const std::unique_ptr<RepeatFunc>& f2)
const {
310 return f1->getNextRunTime() > f2->getNextRunTime();
315 typedef std::unordered_map<StringPiece, RepeatFunc*, Hash>
FunctionMap;
319 std::unique_lock<std::mutex>&
lock,
320 std::chrono::steady_clock::time_point
now);
323 const std::unique_lock<std::mutex>&
lock,
324 std::unique_ptr<RepeatFunc> func);
326 template <
typename RepeatFuncNextRunTimeFunc>
329 RepeatFuncNextRunTimeFunc&& fn,
332 std::chrono::milliseconds startDelay,
340 std::chrono::milliseconds startDelay,
347 std::chrono::milliseconds startDelay,
353 std::unique_lock<std::mutex>&
lock,
void addFunctionOnce(Function< void()> &&cb, StringPiece nameID=StringPiece(), std::chrono::milliseconds startDelay=std::chrono::milliseconds(0))
void addFunction(Function< void()> &&cb, std::chrono::milliseconds interval, StringPiece nameID=StringPiece(), std::chrono::milliseconds startDelay=std::chrono::milliseconds(0))
LatencyDistribution(bool poisson, double mean)
std::chrono::steady_clock::time_point getNextRunTime() const
RepeatFunc * currentFunction_
bool cancelFunctionWithLock(std::unique_lock< std::mutex > &lock, StringPiece nameID)
std::chrono::milliseconds startDelay
void addFunctionToHeap(const std::unique_lock< std::mutex > &lock, std::unique_ptr< RepeatFunc > func)
void addFunctionGenericNextRunTimeFunctor(Function< void()> &&cb, NextRunTimeFunc &&fn, const std::string &nameID, const std::string &intervalDescr, std::chrono::milliseconds startDelay)
std::chrono::steady_clock::time_point now()
constexpr detail::Map< Move > move
NextRunTimeFunc nextRunTimeFunc
void addFunctionToHeapChecked(Function< void()> &&cb, RepeatFuncNextRunTimeFunc &&fn, const std::string &nameID, const std::string &intervalDescr, std::chrono::milliseconds startDelay, bool runOnce)
RepeatFunc(Function< void()> &&cback, IntervalDistributionFunc &&intervalFn, const std::string &nameID, const std::string &intervalDistDescription, std::chrono::milliseconds delay, bool once)
—— Concurrent Priority Queue Implementation ——
void cancelAllFunctions()
FunctionMap functionsMap_
std::condition_variable runningCondvar_
void runOneFunction(std::unique_lock< std::mutex > &lock, std::chrono::steady_clock::time_point now)
bool operator()(const std::unique_ptr< RepeatFunc > &f1, const std::unique_ptr< RepeatFunc > &f2) const
bool resetFunctionTimer(StringPiece nameID)
std::chrono::steady_clock::time_point nextRunTime
bool cancelFunction(StringPiece nameID)
void cancelAllFunctionsAndWait()
void setNextRunTimeSteady()
auto lock(Synchronized< D, M > &synchronized, Args &&...args)
void resetNextRunTime(std::chrono::steady_clock::time_point curTime)
std::string intervalDescr
std::vector< std::unique_ptr< RepeatFunc > > FunctionHeap
void addFunctionInternal(Function< void()> &&cb, NextRunTimeFunc &&fn, const std::string &nameID, const std::string &intervalDescr, std::chrono::milliseconds startDelay, bool runOnce)
void addFunctionUniformDistribution(Function< void()> &&cb, std::chrono::milliseconds minInterval, std::chrono::milliseconds maxInterval, StringPiece nameID, std::chrono::milliseconds startDelay)
bool cancelAllFunctionsWithLock(std::unique_lock< std::mutex > &lock)
bool cancelFunctionAndWait(StringPiece nameID)
bool cancellingCurrentFunction_
void setNextRunTimeStrict(std::chrono::steady_clock::time_point curTime)
void addFunctionConsistentDelay(Function< void()> &&cb, std::chrono::milliseconds interval, StringPiece nameID=StringPiece(), std::chrono::milliseconds startDelay=std::chrono::milliseconds(0))
void setThreadName(StringPiece threadName)
Range< const char * > StringPiece
void addFunctionGenericDistribution(Function< void()> &&cb, IntervalDistributionFunc &&intervalFunc, const std::string &nameID, const std::string &intervalDescr, std::chrono::milliseconds startDelay)
static NextRunTimeFunc getNextRunTimeFunc(IntervalDistributionFunc &&intervalFn)
RepeatFunc(Function< void()> &&cback, NextRunTimeFunc &&nextRunTimeFn, const std::string &nameID, const std::string &intervalDistDescription, std::chrono::milliseconds delay, bool once)
void setSteady(bool steady)
std::unordered_map< StringPiece, RepeatFunc *, Hash > FunctionMap