Unverified Commit 29c9d443 authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #742 from capnproto/busy-poll-interval

Add a way to set a maximum number of event loop turns before we poll for input.
parents 46ed8793 327555fc
...@@ -436,10 +436,16 @@ void waitImpl(Own<_::PromiseNode>&& node, _::ExceptionOrValue& result, WaitScope ...@@ -436,10 +436,16 @@ void waitImpl(Own<_::PromiseNode>&& node, _::ExceptionOrValue& result, WaitScope
loop.running = true; loop.running = true;
KJ_DEFER(loop.running = false); KJ_DEFER(loop.running = false);
uint counter = 0;
while (!doneEvent.fired) { while (!doneEvent.fired) {
if (!loop.turn()) { if (!loop.turn()) {
// No events in the queue. Wait for callback. // No events in the queue. Wait for callback.
counter = 0;
loop.port.wait(); loop.port.wait();
} else if (++counter > waitScope.busyPollInterval) {
// Note: It's intentional that if busyPollInterval is kj::maxValue, we never poll.
counter = 0;
loop.port.poll();
} }
} }
......
...@@ -798,8 +798,13 @@ public: ...@@ -798,8 +798,13 @@ public:
void poll(); void poll();
// Pumps the event queue and polls for I/O until there's nothing left to do (without blocking). // Pumps the event queue and polls for I/O until there's nothing left to do (without blocking).
void setBusyPollInterval(uint count) { busyPollInterval = count; }
// Set the maximum number of events to run in a row before calling poll() on the EventPort to
// check for new I/O.
private: private:
EventLoop& loop; EventLoop& loop;
uint busyPollInterval = kj::maxValue;
friend class EventLoop; friend class EventLoop;
friend void _::waitImpl(Own<_::PromiseNode>&& node, _::ExceptionOrValue& result, friend void _::waitImpl(Own<_::PromiseNode>&& node, _::ExceptionOrValue& result,
WaitScope& waitScope); WaitScope& waitScope);
......
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