diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-08-02 20:41:55 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-08-02 21:03:09 (GMT) |
commit | d5ace22054203c7989691ae8b3fa4e4784d1b57e (patch) | |
tree | 64d400cdb10644967df183d0f202fcbf8160a773 /3rdParty/Boost/src/boost/asio/detail/impl/strand_service.ipp | |
parent | 6f26d9aa86f0909af13b23b1a925b8d492e74154 (diff) | |
download | swift-contrib-ks/boost1.47.zip swift-contrib-ks/boost1.47.tar.bz2 |
Add two extra Boost dependencies, upgrade to 1.47.0ks/boost1.47
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/impl/strand_service.ipp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/detail/impl/strand_service.ipp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/impl/strand_service.ipp b/3rdParty/Boost/src/boost/asio/detail/impl/strand_service.ipp index 6a42146..62a8d5c 100644 --- a/3rdParty/Boost/src/boost/asio/detail/impl/strand_service.ipp +++ b/3rdParty/Boost/src/boost/asio/detail/impl/strand_service.ipp @@ -70,11 +70,50 @@ void strand_service::construct(strand_service::implementation_type& impl) boost::asio::detail::mutex::scoped_lock lock(mutex_); - if (!implementations_[index]) + if (!implementations_[index].get()) implementations_[index].reset(new strand_impl); impl = implementations_[index].get(); } +bool strand_service::do_dispatch(implementation_type& impl, operation* op) +{ + // 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(); + return true; + } + + // Immediate invocation is not allowed, so enqueue for later. + impl->queue_.push(op); + impl->mutex_.unlock(); + + // The first handler to be enqueued is responsible for scheduling the + // strand. + if (first) + io_service_.post_immediate_completion(impl); + + return false; +} + +void strand_service::do_post(implementation_type& impl, operation* op) +{ + // Add the handler to the queue. + impl->mutex_.lock(); + bool first = (++impl->count_ == 1); + impl->queue_.push(op); + impl->mutex_.unlock(); + + // The first handler to be enqueue is responsible for scheduling the strand. + if (first) + io_service_.post_immediate_completion(impl); +} + void strand_service::do_complete(io_service_impl* owner, operation* base, boost::system::error_code /*ec*/, std::size_t /*bytes_transferred*/) { |