|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r78666 - in trunk/boost/asio/detail: . impl
From: chris_at_[hidden]
Date: 2012-05-26 18:25:31
Author: chris_kohlhoff
Date: 2012-05-26 18:25:30 EDT (Sat, 26 May 2012)
New Revision: 78666
URL: http://svn.boost.org/trac/boost/changeset/78666
Log:
Eliminate a lock/unlock pair when rescheduling a strand.
Text files modified:
trunk/boost/asio/detail/impl/strand_service.ipp | 2 +-
trunk/boost/asio/detail/impl/task_io_service.ipp | 30 ++++++++++++++++++++++++++++--
trunk/boost/asio/detail/task_io_service.hpp | 10 ++++++++++
trunk/boost/asio/detail/win_iocp_io_service.hpp | 16 ++++++++++++++++
4 files changed, 55 insertions(+), 3 deletions(-)
Modified: trunk/boost/asio/detail/impl/strand_service.ipp
==============================================================================
--- trunk/boost/asio/detail/impl/strand_service.ipp (original)
+++ trunk/boost/asio/detail/impl/strand_service.ipp 2012-05-26 18:25:30 EDT (Sat, 26 May 2012)
@@ -38,7 +38,7 @@
impl_->mutex_.unlock();
if (more_handlers)
- owner_->post_immediate_completion(impl_);
+ owner_->post_private_immediate_completion(impl_);
}
};
Modified: trunk/boost/asio/detail/impl/task_io_service.ipp
==============================================================================
--- trunk/boost/asio/detail/impl/task_io_service.ipp (original)
+++ trunk/boost/asio/detail/impl/task_io_service.ipp 2012-05-26 18:25:30 EDT (Sat, 26 May 2012)
@@ -133,7 +133,7 @@
this_thread.wakeup_event = &wakeup_event;
op_queue<operation> private_op_queue;
#if defined(BOOST_HAS_THREADS) && !defined(BOOST_ASIO_DISABLE_THREADS)
- this_thread.private_op_queue = one_thread_ == 1 ? &private_op_queue : 0;
+ this_thread.private_op_queue = &private_op_queue;
#else // defined(BOOST_HAS_THREADS) && !defined(BOOST_ASIO_DISABLE_THREADS)
this_thread.private_op_queue = 0;
#endif // defined(BOOST_HAS_THREADS) && !defined(BOOST_ASIO_DISABLE_THREADS)
@@ -184,7 +184,7 @@
this_thread.wakeup_event = 0;
op_queue<operation> private_op_queue;
#if defined(BOOST_HAS_THREADS) && !defined(BOOST_ASIO_DISABLE_THREADS)
- this_thread.private_op_queue = one_thread_ == 1 ? &private_op_queue : 0;
+ this_thread.private_op_queue = &private_op_queue;
#else // defined(BOOST_HAS_THREADS) && !defined(BOOST_ASIO_DISABLE_THREADS)
this_thread.private_op_queue = 0;
#endif // defined(BOOST_HAS_THREADS) && !defined(BOOST_ASIO_DISABLE_THREADS)
@@ -311,6 +311,32 @@
}
}
+void task_io_service::post_private_immediate_completion(
+ task_io_service::operation* op)
+{
+ work_started();
+ post_private_deferred_completion(op);
+}
+
+void task_io_service::post_private_deferred_completion(
+ task_io_service::operation* op)
+{
+#if defined(BOOST_HAS_THREADS) && !defined(BOOST_ASIO_DISABLE_THREADS)
+ if (thread_info* this_thread = thread_call_stack::contains(this))
+ {
+ if (this_thread->private_op_queue)
+ {
+ this_thread->private_op_queue->push(op);
+ return;
+ }
+ }
+#endif // defined(BOOST_HAS_THREADS) && !defined(BOOST_ASIO_DISABLE_THREADS)
+
+ mutex::scoped_lock lock(mutex_);
+ op_queue_.push(op);
+ wake_one_thread_and_unlock(lock);
+}
+
void task_io_service::abandon_operations(
op_queue<task_io_service::operation>& ops)
{
Modified: trunk/boost/asio/detail/task_io_service.hpp
==============================================================================
--- trunk/boost/asio/detail/task_io_service.hpp (original)
+++ trunk/boost/asio/detail/task_io_service.hpp 2012-05-26 18:25:30 EDT (Sat, 26 May 2012)
@@ -112,6 +112,16 @@
// that work_started() was previously called for each operation.
BOOST_ASIO_DECL void post_deferred_completions(op_queue<operation>& ops);
+ // Request invocation of the given operation using the thread-private queue
+ // and return immediately. Assumes that work_started() has not yet been
+ // called for the operation.
+ BOOST_ASIO_DECL void post_private_immediate_completion(operation* op);
+
+ // Request invocation of the given operation using the thread-private queue
+ // and return immediately. Assumes that work_started() was previously called
+ // for the operation.
+ BOOST_ASIO_DECL void post_private_deferred_completion(operation* op);
+
// Process unfinished operations as part of a shutdown_service operation.
// Assumes that work_started() was previously called for the operations.
BOOST_ASIO_DECL void abandon_operations(op_queue<operation>& ops);
Modified: trunk/boost/asio/detail/win_iocp_io_service.hpp
==============================================================================
--- trunk/boost/asio/detail/win_iocp_io_service.hpp (original)
+++ trunk/boost/asio/detail/win_iocp_io_service.hpp 2012-05-26 18:25:30 EDT (Sat, 26 May 2012)
@@ -135,6 +135,22 @@
BOOST_ASIO_DECL void post_deferred_completions(
op_queue<win_iocp_operation>& ops);
+ // Request invocation of the given operation using the thread-private queue
+ // and return immediately. Assumes that work_started() has not yet been
+ // called for the operation.
+ void post_private_immediate_completion(win_iocp_operation* op)
+ {
+ post_immediate_completion(op);
+ }
+
+ // Request invocation of the given operation using the thread-private queue
+ // and return immediately. Assumes that work_started() was previously called
+ // for the operation.
+ void post_private_deferred_completion(win_iocp_operation* op)
+ {
+ post_deferred_completion(op);
+ }
+
// Process unfinished operations as part of a shutdown_service operation.
// Assumes that work_started() was previously called for the operations.
BOOST_ASIO_DECL void abandon_operations(op_queue<operation>& ops);
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