diff options
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/impl/strand_service.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/detail/impl/strand_service.hpp | 58 |
1 files changed, 16 insertions, 42 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/impl/strand_service.hpp b/3rdParty/Boost/src/boost/asio/detail/impl/strand_service.hpp index 5cb320d..7581852 100644 --- a/3rdParty/Boost/src/boost/asio/detail/impl/strand_service.hpp +++ b/3rdParty/Boost/src/boost/asio/detail/impl/strand_service.hpp @@ -2,7 +2,7 @@ // detail/impl/strand_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -29,7 +29,7 @@ namespace detail { inline strand_service::strand_impl::strand_impl() : operation(&strand_service::do_complete), - count_(0) + locked_(false) { } @@ -41,7 +41,8 @@ struct strand_service::on_dispatch_exit ~on_dispatch_exit() { impl_->mutex_.lock(); - bool more_handlers = (--impl_->count_ > 0); + impl_->ready_queue_.push(impl_->waiting_queue_); + bool more_handlers = impl_->locked_ = !impl_->ready_queue_.empty(); impl_->mutex_.unlock(); if (more_handlers) @@ -49,11 +50,6 @@ struct strand_service::on_dispatch_exit } }; -inline void strand_service::destroy(strand_service::implementation_type& impl) -{ - impl = 0; -} - template <typename Handler> void strand_service::dispatch(strand_service::implementation_type& impl, Handler handler) @@ -61,7 +57,7 @@ void strand_service::dispatch(strand_service::implementation_type& impl, // If we are already in the strand then the handler can run immediately. if (call_stack<strand_impl>::contains(impl)) { - boost::asio::detail::fenced_block b; + fenced_block b(fenced_block::full); boost_asio_handler_invoke_helpers::invoke(handler, handler); return; } @@ -73,19 +69,14 @@ void strand_service::dispatch(strand_service::implementation_type& impl, sizeof(op), handler), 0 }; p.p = new (p.v) op(handler); - // If we are running inside the io_service, and no other handler is queued - // or running, then the handler can run immediately. - bool can_dispatch = call_stack<io_service_impl>::contains(&io_service_); - impl->mutex_.lock(); - bool first = (++impl->count_ == 1); - if (can_dispatch && first) - { - // Immediate invocation is allowed. - impl->mutex_.unlock(); + BOOST_ASIO_HANDLER_CREATION((p.p, "strand", impl, "dispatch")); - // Memory must be releaesed before any upcall is made. - p.reset(); + bool dispatch_immediately = do_dispatch(impl, p.p); + operation* o = p.p; + p.v = p.p = 0; + if (dispatch_immediately) + { // Indicate that this strand is executing on the current thread. call_stack<strand_impl>::context ctx(impl); @@ -93,20 +84,9 @@ void strand_service::dispatch(strand_service::implementation_type& impl, on_dispatch_exit on_exit = { &io_service_, impl }; (void)on_exit; - boost::asio::detail::fenced_block b; - boost_asio_handler_invoke_helpers::invoke(handler, handler); - return; + completion_handler<Handler>::do_complete( + &io_service_, o, boost::system::error_code(), 0); } - - // Immediate invocation is not allowed, so enqueue for later. - impl->queue_.push(p.p); - impl->mutex_.unlock(); - p.v = p.p = 0; - - // The first handler to be enqueued is responsible for scheduling the - // strand. - if (first) - io_service_.post_immediate_completion(impl); } // Request the io_service to invoke the given handler and return immediately. @@ -121,16 +101,10 @@ void strand_service::post(strand_service::implementation_type& impl, sizeof(op), handler), 0 }; p.p = new (p.v) op(handler); - // Add the handler to the queue. - impl->mutex_.lock(); - bool first = (++impl->count_ == 1); - impl->queue_.push(p.p); - impl->mutex_.unlock(); - p.v = p.p = 0; + BOOST_ASIO_HANDLER_CREATION((p.p, "strand", impl, "post")); - // The first handler to be enqueue is responsible for scheduling the strand. - if (first) - io_service_.post_immediate_completion(impl); + do_post(impl, p.p); + p.v = p.p = 0; } } // namespace detail |