Boost logo

Boost-Commit :

From: chris_at_[hidden]
Date: 2008-01-14 08:24:29


Author: chris_kohlhoff
Date: 2008-01-14 08:24:28 EST (Mon, 14 Jan 2008)
New Revision: 42755
URL: http://svn.boost.org/trac/boost/changeset/42755

Log:
Don't call epoll_wait/kevent if there are no old operations (where old means
added prior to the last epoll_wait/kevent call) needing to be demultiplexed.

Text files modified:
   trunk/boost/asio/detail/epoll_reactor.hpp | 14 ++++++++++++--
   trunk/boost/asio/detail/kqueue_reactor.hpp | 14 ++++++++++++--
   2 files changed, 24 insertions(+), 4 deletions(-)

Modified: trunk/boost/asio/detail/epoll_reactor.hpp
==============================================================================
--- trunk/boost/asio/detail/epoll_reactor.hpp (original)
+++ trunk/boost/asio/detail/epoll_reactor.hpp 2008-01-14 08:24:28 EST (Mon, 14 Jan 2008)
@@ -67,7 +67,8 @@
       pending_cancellations_(),
       stop_thread_(false),
       thread_(0),
- shutdown_(false)
+ shutdown_(false),
+ need_epoll_wait_(true)
   {
     // Start the reactor's internal thread only if needed.
     if (Own_Thread)
@@ -388,7 +389,9 @@
 
     // Block on the epoll descriptor.
     epoll_event events[128];
- int num_events = epoll_wait(epoll_fd_, events, 128, timeout);
+ int num_events = (block || need_epoll_wait_)
+ ? epoll_wait(epoll_fd_, events, 128, timeout)
+ : 0;
 
     lock.lock();
     wait_in_progress_ = false;
@@ -479,6 +482,10 @@
       cancel_ops_unlocked(pending_cancellations_[i]);
     pending_cancellations_.clear();
 
+ // Determine whether epoll_wait should be called when the reactor next runs.
+ need_epoll_wait_ = !read_op_queue_.empty()
+ || !write_op_queue_.empty() || !except_op_queue_.empty();
+
     cleanup_operations_and_timers(lock);
   }
 
@@ -633,6 +640,9 @@
 
   // Whether the service has been shut down.
   bool shutdown_;
+
+ // Whether we need to call epoll_wait the next time the reactor is run.
+ bool need_epoll_wait_;
 };
 
 } // namespace detail

Modified: trunk/boost/asio/detail/kqueue_reactor.hpp
==============================================================================
--- trunk/boost/asio/detail/kqueue_reactor.hpp (original)
+++ trunk/boost/asio/detail/kqueue_reactor.hpp 2008-01-14 08:24:28 EST (Mon, 14 Jan 2008)
@@ -75,7 +75,8 @@
       pending_cancellations_(),
       stop_thread_(false),
       thread_(0),
- shutdown_(false)
+ shutdown_(false),
+ need_kqueue_wait_(true)
   {
     // Start the reactor's internal thread only if needed.
     if (Own_Thread)
@@ -374,7 +375,9 @@
 
     // Block on the kqueue descriptor.
     struct kevent events[128];
- int num_events = kevent(kqueue_fd_, 0, 0, events, 128, timeout);
+ int num_events = (block || need_kqueue_wait_)
+ ? kevent(kqueue_fd_, 0, 0, events, 128, timeout)
+ : 0;
 
     lock.lock();
     wait_in_progress_ = false;
@@ -479,6 +482,10 @@
       cancel_ops_unlocked(pending_cancellations_[i]);
     pending_cancellations_.clear();
 
+ // Determine whether kqueue needs to be called next time the reactor is run.
+ need_kqueue_wait_ = !read_op_queue_.empty()
+ || !write_op_queue_.empty() || !except_op_queue_.empty();
+
     cleanup_operations_and_timers(lock);
   }
 
@@ -631,6 +638,9 @@
 
   // Whether the service has been shut down.
   bool shutdown_;
+
+ // Whether we need to call kqueue the next time the reactor is run.
+ bool need_kqueue_wait_;
 };
 
 } // namespace detail


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk