From aee08623808a83c9f2449a6ff91d15c384af2e92 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Sat, 7 Jan 2017 12:51:20 -0800 Subject: [PATCH] std::chrono'ize EventBase::setMaxLatency Summary: Onward towards more modern code! Reviewed By: yfeldblum Differential Revision: D4377678 fbshipit-source-id: 6ca5ecd902be9028fb55f139374f7919fa522899 --- folly/io/async/EventBase.cpp | 6 +++--- folly/io/async/EventBase.h | 4 ++-- folly/io/async/test/EventBaseTest.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index 24883d9b..33fdfa8c 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -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 diff --git a/folly/io/async/EventBase.h b/folly/io/async/EventBase.h index 4799ee2e..20d282b5 100644 --- a/folly/io/async/EventBase.h +++ b/folly/io/async/EventBase.h @@ -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_; diff --git a/folly/io/async/test/EventBaseTest.cpp b/folly/io/async/test/EventBaseTest.cpp index b952640f..454ece3c 100644 --- a/folly/io/async/test/EventBaseTest.cpp +++ b/folly/io/async/test/EventBaseTest.cpp @@ -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"; -- 2.34.1