From cc34dbb84090f74c84037afb269003f13aa46b78 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 10 Feb 2014 19:59:35 -0800 Subject: Expose whether event loops have active I/O The green scheduler can optimize its runtime based on this by deciding to not go to sleep in epoll() if there is no active I/O and there is a task to be stolen. This is implemented for librustuv by keeping a count of the number of tasks which are currently homed. If a task is homed, and then performs a blocking I/O operation, the count will be nonzero while the task is blocked. The homing count is intentionally 0 when there are I/O handles, but no handles currently blocked. The reason for this is that epoll() would only be used to wake up the scheduler anyway. The crux of this change was to have a `HomingMissile` contain a mutable borrowed reference back to the `HomeHandle`. The rest of the change was just dealing with this fallout. This reference is used to decrement the homed handle count in a HomingMissile's destructor. Also note that the count maintained is not atomic because all of its increments/decrements/reads are all on the same I/O thread. --- src/libstd/rt/rtio.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libstd/rt') diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index 39623e329ea..5573f8ec02e 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -41,6 +41,7 @@ pub trait EventLoop { /// The asynchronous I/O services. Not all event loops may provide one. fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory>; + fn has_active_io(&self) -> bool; } pub trait RemoteCallback { -- cgit 1.4.1-3-g733a5