From f099d2b48d75cb98f21e62b5dfca344c96588ffe Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Mon, 11 May 2015 18:32:56 -0700 Subject: [PATCH] expose FunctionScheduler::addFunction() with a custom distribution Summary: Make addFunctionInternal() publicly available, as an overloaded version of addFunction(). This allows users to add functions with a specified poisson distribution. This allows us to deprecate our internal legacy version of FunctionScheduler, and replace it with the folly version. Test Plan: Confirmed all unit tests still pass. Reviewed By: ldbrandy@fb.com Subscribers: jwatzman, doug, net-systems@, exa, folly-diffs@, yfeldblum, chalfant FB internal diff: D2051699 Signature: t1:2051699:1431379841:f3547d1ed371503b0bf91b509a4ef03e881aa991 --- folly/experimental/FunctionScheduler.cpp | 5 ++-- folly/experimental/FunctionScheduler.h | 30 +++++++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/folly/experimental/FunctionScheduler.cpp b/folly/experimental/FunctionScheduler.cpp index b2c637aa..e9ea7543 100644 --- a/folly/experimental/FunctionScheduler.cpp +++ b/folly/experimental/FunctionScheduler.cpp @@ -38,11 +38,10 @@ void FunctionScheduler::addFunction(const std::function& cb, StringPiece nameID, milliseconds startDelay) { LatencyDistribution latencyDistr(false, 0.0); - addFunctionInternal(cb, interval, - latencyDistr, nameID, startDelay); + addFunction(cb, interval, latencyDistr, nameID, startDelay); } -void FunctionScheduler::addFunctionInternal(const std::function& cb, +void FunctionScheduler::addFunction(const std::function& cb, milliseconds interval, const LatencyDistribution& latencyDistr, StringPiece nameID, diff --git a/folly/experimental/FunctionScheduler.h b/folly/experimental/FunctionScheduler.h index 896cb1fd..1e8802fe 100644 --- a/folly/experimental/FunctionScheduler.h +++ b/folly/experimental/FunctionScheduler.h @@ -64,16 +64,23 @@ class FunctionScheduler { */ void setSteady(bool steady) { steady_ = steady; } + /* + * Parameters to control the function interval. + * + * If isPoisson is true, then use std::poisson_distribution to pick the + * interval between each invocation of the function. + * + * If isPoisson os false, then always use fixed the interval specified to + * addFunction(). + */ struct LatencyDistribution { bool isPoisson; double poissonMean; - LatencyDistribution(bool poisson, - double mean) + LatencyDistribution(bool poisson, double mean) : isPoisson(poisson), poissonMean(mean) { } - }; /** @@ -93,6 +100,17 @@ class FunctionScheduler { std::chrono::milliseconds startDelay = std::chrono::milliseconds(0)); + /* + * Add a new function to the FunctionScheduler with a specified + * LatencyDistribution + */ + void addFunction(const std::function& cb, + std::chrono::milliseconds interval, + const LatencyDistribution& latencyDistr, + StringPiece nameID = StringPiece(), + std::chrono::milliseconds startDelay = + std::chrono::milliseconds(0)); + /** * Cancels the function with the specified name, so it will no longer be run. * @@ -126,12 +144,6 @@ class FunctionScheduler { private: - void addFunctionInternal(const std::function& cb, - std::chrono::milliseconds interval, - const LatencyDistribution& latencyDistr, - StringPiece nameID = StringPiece(), - std::chrono::milliseconds startDelay = - std::chrono::milliseconds(0)); struct RepeatFunc { std::function cb; std::chrono::milliseconds timeInterval; -- 2.34.1