Commit b6d2974b authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

Back out "Add support for microsecond intervals in the function scheduler"

Summary: Original commit changeset: 10f18d7b774c

Reviewed By: arushiagg

Differential Revision: D23431208

fbshipit-source-id: d2c79f81fd0ada202dc2eaa96b0f061828ca107e
parent 041d632a
......@@ -25,7 +25,7 @@
#include <folly/String.h>
#include <folly/system/ThreadName.h>
using std::chrono::microseconds;
using std::chrono::milliseconds;
using std::chrono::steady_clock;
namespace folly {
......@@ -33,11 +33,11 @@ namespace folly {
namespace {
struct ConsistentDelayFunctor {
const microseconds constInterval;
const milliseconds constInterval;
explicit ConsistentDelayFunctor(microseconds interval)
explicit ConsistentDelayFunctor(milliseconds interval)
: constInterval(interval) {
if (interval < microseconds::zero()) {
if (interval < milliseconds::zero()) {
throw std::invalid_argument(
"FunctionScheduler: "
"time interval must be non-negative");
......@@ -53,18 +53,18 @@ struct ConsistentDelayFunctor {
};
struct ConstIntervalFunctor {
const microseconds constInterval;
const milliseconds constInterval;
explicit ConstIntervalFunctor(microseconds interval)
explicit ConstIntervalFunctor(milliseconds interval)
: constInterval(interval) {
if (interval < microseconds::zero()) {
if (interval < milliseconds::zero()) {
throw std::invalid_argument(
"FunctionScheduler: "
"time interval must be non-negative");
}
}
microseconds operator()() const {
milliseconds operator()() const {
return constInterval;
}
};
......@@ -82,16 +82,16 @@ struct PoissonDistributionFunctor {
}
}
microseconds operator()() {
return microseconds(poissonRandom(generator));
milliseconds operator()() {
return milliseconds(poissonRandom(generator));
}
};
struct UniformDistributionFunctor {
std::default_random_engine generator;
std::uniform_int_distribution<microseconds::rep> dist;
std::uniform_int_distribution<milliseconds::rep> dist;
UniformDistributionFunctor(microseconds minInterval, microseconds maxInterval)
UniformDistributionFunctor(milliseconds minInterval, milliseconds maxInterval)
: generator(Random::rand32()),
dist(minInterval.count(), maxInterval.count()) {
if (minInterval > maxInterval) {
......@@ -99,15 +99,15 @@ struct UniformDistributionFunctor {
"FunctionScheduler: "
"min time interval must be less or equal than max interval");
}
if (minInterval < microseconds::zero()) {
if (minInterval < milliseconds::zero()) {
throw std::invalid_argument(
"FunctionScheduler: "
"time interval must be non-negative");
}
}
microseconds operator()() {
return microseconds(dist(generator));
milliseconds operator()() {
return milliseconds(dist(generator));
}
};
......@@ -122,9 +122,9 @@ FunctionScheduler::~FunctionScheduler() {
void FunctionScheduler::addFunction(
Function<void()>&& cb,
microseconds interval,
milliseconds interval,
StringPiece nameID,
microseconds startDelay) {
milliseconds startDelay) {
addFunctionInternal(
std::move(cb),
ConstIntervalFunctor(interval),
......@@ -136,10 +136,10 @@ void FunctionScheduler::addFunction(
void FunctionScheduler::addFunction(
Function<void()>&& cb,
microseconds interval,
milliseconds interval,
const LatencyDistribution& latencyDistr,
StringPiece nameID,
microseconds startDelay) {
milliseconds startDelay) {
if (latencyDistr.isPoisson) {
addFunctionInternal(
std::move(cb),
......@@ -156,10 +156,10 @@ void FunctionScheduler::addFunction(
void FunctionScheduler::addFunctionOnce(
Function<void()>&& cb,
StringPiece nameID,
microseconds startDelay) {
milliseconds startDelay) {
addFunctionInternal(
std::move(cb),
ConstIntervalFunctor(microseconds::zero()),
ConstIntervalFunctor(milliseconds::zero()),
nameID.str(),
"once",
startDelay,
......@@ -168,10 +168,10 @@ void FunctionScheduler::addFunctionOnce(
void FunctionScheduler::addFunctionUniformDistribution(
Function<void()>&& cb,
microseconds minInterval,
microseconds maxInterval,
milliseconds minInterval,
milliseconds maxInterval,
StringPiece nameID,
microseconds startDelay) {
milliseconds startDelay) {
addFunctionInternal(
std::move(cb),
UniformDistributionFunctor(minInterval, maxInterval),
......@@ -184,9 +184,9 @@ void FunctionScheduler::addFunctionUniformDistribution(
void FunctionScheduler::addFunctionConsistentDelay(
Function<void()>&& cb,
microseconds interval,
milliseconds interval,
StringPiece nameID,
microseconds startDelay) {
milliseconds startDelay) {
addFunctionInternal(
std::move(cb),
ConsistentDelayFunctor(interval),
......@@ -201,7 +201,7 @@ void FunctionScheduler::addFunctionGenericDistribution(
IntervalDistributionFunc&& intervalFunc,
const std::string& nameID,
const std::string& intervalDescr,
microseconds startDelay) {
milliseconds startDelay) {
addFunctionInternal(
std::move(cb),
std::move(intervalFunc),
......@@ -216,7 +216,7 @@ void FunctionScheduler::addFunctionGenericNextRunTimeFunctor(
NextRunTimeFunc&& fn,
const std::string& nameID,
const std::string& intervalDescr,
microseconds startDelay) {
milliseconds startDelay) {
addFunctionInternal(
std::move(cb),
std::move(fn),
......@@ -232,7 +232,7 @@ void FunctionScheduler::addFunctionToHeapChecked(
RepeatFuncNextRunTimeFunc&& fn,
const std::string& nameID,
const std::string& intervalDescr,
microseconds startDelay,
milliseconds startDelay,
bool runOnce) {
if (!cb) {
throw std::invalid_argument(
......@@ -243,7 +243,7 @@ void FunctionScheduler::addFunctionToHeapChecked(
"FunctionScheduler: "
"interval distribution or next run time function must be set");
}
if (startDelay < microseconds::zero()) {
if (startDelay < milliseconds::zero()) {
throw std::invalid_argument(
"FunctionScheduler: start delay must be non-negative");
}
......@@ -277,7 +277,7 @@ void FunctionScheduler::addFunctionInternal(
NextRunTimeFunc&& fn,
const std::string& nameID,
const std::string& intervalDescr,
microseconds startDelay,
milliseconds startDelay,
bool runOnce) {
return addFunctionToHeapChecked(
std::move(cb), std::move(fn), nameID, intervalDescr, startDelay, runOnce);
......@@ -288,7 +288,7 @@ void FunctionScheduler::addFunctionInternal(
IntervalDistributionFunc&& fn,
const std::string& nameID,
const std::string& intervalDescr,
microseconds startDelay,
milliseconds startDelay,
bool runOnce) {
return addFunctionToHeapChecked(
std::move(cb), std::move(fn), nameID, intervalDescr, startDelay, runOnce);
......@@ -465,7 +465,7 @@ void FunctionScheduler::run() {
}
auto sleepTime = functions_.back()->getNextRunTime() - now;
if (sleepTime < microseconds::zero()) {
if (sleepTime < milliseconds::zero()) {
// We need to run this function now
runOneFunction(lock, now);
runningCondvar_.notify_all();
......
......@@ -99,9 +99,9 @@ class FunctionScheduler {
*/
void addFunction(
Function<void()>&& cb,
std::chrono::microseconds interval,
std::chrono::milliseconds interval,
StringPiece nameID = StringPiece(),
std::chrono::microseconds startDelay = std::chrono::microseconds(0));
std::chrono::milliseconds startDelay = std::chrono::milliseconds(0));
/*
* Add a new function to the FunctionScheduler with a specified
......@@ -109,10 +109,10 @@ class FunctionScheduler {
*/
void addFunction(
Function<void()>&& cb,
std::chrono::microseconds interval,
std::chrono::milliseconds interval,
const LatencyDistribution& latencyDistr,
StringPiece nameID = StringPiece(),
std::chrono::microseconds startDelay = std::chrono::microseconds(0));
std::chrono::milliseconds startDelay = std::chrono::milliseconds(0));
/**
* Adds a new function to the FunctionScheduler to run only once.
......@@ -120,7 +120,7 @@ class FunctionScheduler {
void addFunctionOnce(
Function<void()>&& cb,
StringPiece nameID = StringPiece(),
std::chrono::microseconds startDelay = std::chrono::microseconds(0));
std::chrono::milliseconds startDelay = std::chrono::milliseconds(0));
/**
* Add a new function to the FunctionScheduler with the time
......@@ -129,10 +129,10 @@ class FunctionScheduler {
*/
void addFunctionUniformDistribution(
Function<void()>&& cb,
std::chrono::microseconds minInterval,
std::chrono::microseconds maxInterval,
std::chrono::milliseconds minInterval,
std::chrono::milliseconds maxInterval,
StringPiece nameID,
std::chrono::microseconds startDelay);
std::chrono::milliseconds startDelay);
/**
* Add a new function to the FunctionScheduler whose start times are attempted
......@@ -143,15 +143,15 @@ class FunctionScheduler {
*/
void addFunctionConsistentDelay(
Function<void()>&& cb,
std::chrono::microseconds interval,
std::chrono::milliseconds interval,
StringPiece nameID = StringPiece(),
std::chrono::microseconds startDelay = std::chrono::microseconds(0));
std::chrono::milliseconds startDelay = std::chrono::milliseconds(0));
/**
* A type alias for function that is called to determine the time
* interval for the next scheduled run.
*/
using IntervalDistributionFunc = Function<std::chrono::microseconds()>;
using IntervalDistributionFunc = Function<std::chrono::milliseconds()>;
/**
* A type alias for function that returns the next run time, given the current
* run time and the current start time.
......@@ -174,7 +174,7 @@ class FunctionScheduler {
IntervalDistributionFunc&& intervalFunc,
const std::string& nameID,
const std::string& intervalDescr,
std::chrono::microseconds startDelay);
std::chrono::milliseconds startDelay);
/**
* Like addFunctionGenericDistribution, adds a new function to the
......@@ -186,7 +186,7 @@ class FunctionScheduler {
NextRunTimeFunc&& fn,
const std::string& nameID,
const std::string& intervalDescr,
std::chrono::microseconds startDelay);
std::chrono::milliseconds startDelay);
/**
* Cancels the function with the specified name, so it will no longer be run.
......@@ -239,7 +239,7 @@ class FunctionScheduler {
NextRunTimeFunc nextRunTimeFunc;
std::chrono::steady_clock::time_point nextRunTime;
std::string name;
std::chrono::microseconds startDelay;
std::chrono::milliseconds startDelay;
std::string intervalDescr;
bool runOnce;
......@@ -248,7 +248,7 @@ class FunctionScheduler {
IntervalDistributionFunc&& intervalFn,
const std::string& nameID,
const std::string& intervalDistDescription,
std::chrono::microseconds delay,
std::chrono::milliseconds delay,
bool once)
: RepeatFunc(
std::move(cback),
......@@ -263,7 +263,7 @@ class FunctionScheduler {
NextRunTimeFunc&& nextRunTimeFn,
const std::string& nameID,
const std::string& intervalDistDescription,
std::chrono::microseconds delay,
std::chrono::milliseconds delay,
bool once)
: cb(std::move(cback)),
nextRunTimeFunc(std::move(nextRunTimeFn)),
......@@ -329,7 +329,7 @@ class FunctionScheduler {
RepeatFuncNextRunTimeFunc&& fn,
const std::string& nameID,
const std::string& intervalDescr,
std::chrono::microseconds startDelay,
std::chrono::milliseconds startDelay,
bool runOnce);
void addFunctionInternal(
......@@ -337,14 +337,14 @@ class FunctionScheduler {
NextRunTimeFunc&& fn,
const std::string& nameID,
const std::string& intervalDescr,
std::chrono::microseconds startDelay,
std::chrono::milliseconds startDelay,
bool runOnce);
void addFunctionInternal(
Function<void()>&& cb,
IntervalDistributionFunc&& fn,
const std::string& nameID,
const std::string& intervalDescr,
std::chrono::microseconds startDelay,
std::chrono::milliseconds startDelay,
bool runOnce);
// Return true if the current function is being canceled
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment