summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
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.ipp41
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*/)
{