From 02cae39d6c0c8f67e788d6f3b282ad22a4240194 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Fri, 6 Jan 2017 14:00:46 -0800 Subject: [PATCH] std::chrono'ize EventBase::setLoadAvgMsec Summary: Modernization is good. Reviewed By: yfeldblum Differential Revision: D4377612 fbshipit-source-id: adb03d8a92f25c8a792c8e7240a93ab20180b038 --- folly/io/async/EventBase.cpp | 4 ++-- folly/io/async/EventBase.h | 2 +- folly/io/async/test/EventBaseTest.cpp | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index 9605b5c7..24883d9b 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -205,10 +205,10 @@ void EventBase::setMaxReadAtOnce(uint32_t maxAtOnce) { // Set smoothing coefficient for loop load average; input is # of milliseconds // for exp(-1) decay. -void EventBase::setLoadAvgMsec(uint32_t ms) { +void EventBase::setLoadAvgMsec(std::chrono::milliseconds ms) { assert(enableTimeMeasurement_); std::chrono::microseconds us = std::chrono::milliseconds(ms); - if (ms > 0) { + if (ms > std::chrono::milliseconds::zero()) { maxLatencyLoopTime_.setTimeInterval(us); avgLoopTime_.setTimeInterval(us); } else { diff --git a/folly/io/async/EventBase.h b/folly/io/async/EventBase.h index cf7311df..4799ee2e 100644 --- a/folly/io/async/EventBase.h +++ b/folly/io/async/EventBase.h @@ -447,7 +447,7 @@ class EventBase : private boost::noncopyable, * Set smoothing coefficient for loop load average; # of milliseconds * for exp(-1) (1/2.71828...) decay. */ - void setLoadAvgMsec(uint32_t ms); + void setLoadAvgMsec(std::chrono::milliseconds ms); /** * reset the load average to a desired value diff --git a/folly/io/async/test/EventBaseTest.cpp b/folly/io/async/test/EventBaseTest.cpp index 1ca9d2d2..b952640f 100644 --- a/folly/io/async/test/EventBaseTest.cpp +++ b/folly/io/async/test/EventBaseTest.cpp @@ -47,6 +47,8 @@ using std::chrono::milliseconds; using std::chrono::microseconds; using std::chrono::duration_cast; +using namespace std::chrono_literals; + using namespace folly; /////////////////////////////////////////////////////////////////////////// @@ -1563,7 +1565,7 @@ class IdleTimeTimeoutSeries : public AsyncTimeout { */ TEST(EventBaseTest, IdleTime) { EventBase eventBase; - eventBase.setLoadAvgMsec(1000); + eventBase.setLoadAvgMsec(1000ms); eventBase.resetLoadAvg(5900.0); std::deque timeouts0(4, 8080); timeouts0.push_front(8000); -- 2.34.1