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