Commit aee08623 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

std::chrono'ize EventBase::setMaxLatency

Summary: Onward towards more modern code!

Reviewed By: yfeldblum

Differential Revision: D4377678

fbshipit-source-id: 6ca5ecd902be9028fb55f139374f7919fa522899
parent 8f22c4e3
......@@ -331,13 +331,13 @@ bool EventBase::loopBody(int flags) {
" busy time: " << busy <<
" avgLoopTime: " << avgLoopTime_.get() <<
" maxLatencyLoopTime: " << maxLatencyLoopTime_.get() <<
" maxLatency_: " << maxLatency_ <<
" maxLatency_: " << maxLatency_.count() << "us" <<
" notificationQueueSize: " << getNotificationQueueSize() <<
" nothingHandledYet(): "<< nothingHandledYet();
// see if our average loop time has exceeded our limit
if ((maxLatency_ > 0) &&
(maxLatencyLoopTime_.get() > double(maxLatency_))) {
if ((maxLatency_ > std::chrono::microseconds::zero()) &&
(maxLatencyLoopTime_.get() > double(maxLatency_.count()))) {
maxLatencyCob_();
// back off temporarily -- don't keep spamming maxLatencyCob_
// if we're only a bit over the limit
......
......@@ -437,7 +437,7 @@ class EventBase : private boost::noncopyable,
* called when that latency is exceeded.
* OBS: This functionality depends on time-measurement.
*/
void setMaxLatency(int64_t maxLatency, Func maxLatencyCob) {
void setMaxLatency(std::chrono::microseconds maxLatency, Func maxLatencyCob) {
assert(enableTimeMeasurement_);
maxLatency_ = maxLatency;
maxLatencyCob_ = std::move(maxLatencyCob);
......@@ -703,7 +703,7 @@ class EventBase : private boost::noncopyable,
bool loopKeepAliveActive_{false};
// limit for latency in microseconds (0 disables)
int64_t maxLatency_;
std::chrono::microseconds maxLatency_;
// exponentially-smoothed average loop time for latency-limiting
SmoothLoopTime avgLoopTime_;
......
......@@ -1578,7 +1578,7 @@ TEST(EventBaseTest, IdleTime) {
bool hostOverloaded = false;
int latencyCallbacks = 0;
eventBase.setMaxLatency(6000, [&]() {
eventBase.setMaxLatency(6000us, [&]() {
++latencyCallbacks;
if (latencyCallbacks != 1) {
FAIL() << "Unexpected latency callback";
......
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