std::chrono'ize EventBase::setMaxLatency
authorChristopher Dykes <cdykes@fb.com>
Sat, 7 Jan 2017 20:51:20 +0000 (12:51 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sat, 7 Jan 2017 21:03:09 +0000 (13:03 -0800)
Summary: Onward towards more modern code!

Reviewed By: yfeldblum

Differential Revision: D4377678

fbshipit-source-id: 6ca5ecd902be9028fb55f139374f7919fa522899

folly/io/async/EventBase.cpp
folly/io/async/EventBase.h
folly/io/async/test/EventBaseTest.cpp

index 24883d9b96a2f387439ccaa46265ef7d3239f4c8..33fdfa8c9a2ea00028ca63326ebf831b4719b4b1 100644 (file)
@@ -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
index 4799ee2e8debebbcec27e7f0083256bfffaf3b26..20d282b5f62642d71048d24f24b453dc7e6a1401 100644 (file)
@@ -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_;
index b952640feea43e0b8b72c0038267c58858768a63..454ece3c55dd7d697a79c8d9d8c48a829bec854a 100644 (file)
@@ -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";