diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-05-06 17:44:27 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-05-06 17:44:27 (GMT) |
commit | d76ada0ab59634e3333f9eb5a92d0e850f60d7bf (patch) | |
tree | 5eaae441173fad2ec19ba67d6589f28ecd740991 /3rdParty/Boost/src/boost/asio/detail/deadline_timer_service.hpp | |
parent | 6f49e5abee37d37b351d68c01374232eccdac458 (diff) | |
download | swift-contrib-d76ada0ab59634e3333f9eb5a92d0e850f60d7bf.zip swift-contrib-d76ada0ab59634e3333f9eb5a92d0e850f60d7bf.tar.bz2 |
Updated Boost to 1.43.0.
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/deadline_timer_service.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/detail/deadline_timer_service.hpp | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/deadline_timer_service.hpp b/3rdParty/Boost/src/boost/asio/detail/deadline_timer_service.hpp index 7885c9a..5ba21b1 100644 --- a/3rdParty/Boost/src/boost/asio/detail/deadline_timer_service.hpp +++ b/3rdParty/Boost/src/boost/asio/detail/deadline_timer_service.hpp @@ -26,21 +26,20 @@ #include <boost/asio/error.hpp> #include <boost/asio/io_service.hpp> #include <boost/asio/detail/bind_handler.hpp> -#include <boost/asio/detail/handler_base_from_member.hpp> +#include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/noncopyable.hpp> -#include <boost/asio/detail/service_base.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/socket_types.hpp> +#include <boost/asio/detail/timer_op.hpp> #include <boost/asio/detail/timer_queue.hpp> +#include <boost/asio/detail/timer_scheduler.hpp> namespace boost { namespace asio { namespace detail { -template <typename Time_Traits, typename Timer_Scheduler> +template <typename Time_Traits> class deadline_timer_service - : public boost::asio::detail::service_base< - deadline_timer_service<Time_Traits, Timer_Scheduler> > { public: // The time type. @@ -60,9 +59,7 @@ public: // Constructor. deadline_timer_service(boost::asio::io_service& io_service) - : boost::asio::detail::service_base< - deadline_timer_service<Time_Traits, Timer_Scheduler> >(io_service), - scheduler_(boost::asio::use_service<Timer_Scheduler>(io_service)) + : scheduler_(boost::asio::use_service<timer_scheduler>(io_service)) { scheduler_.init_task(); scheduler_.add_timer_queue(timer_queue_); @@ -156,34 +153,58 @@ public: } template <typename Handler> - class wait_handler : - public handler_base_from_member<Handler> + class wait_handler : public timer_op { public: - wait_handler(boost::asio::io_service& io_service, Handler handler) - : handler_base_from_member<Handler>(handler), - io_service_(io_service), - work_(io_service) + wait_handler(Handler handler) + : timer_op(&wait_handler::do_complete), + handler_(handler) { } - void operator()(const boost::system::error_code& result) + static void do_complete(io_service_impl* owner, operation* base, + boost::system::error_code /*ec*/, std::size_t /*bytes_transferred*/) { - io_service_.post(detail::bind_handler(this->handler_, result)); + // Take ownership of the handler object. + wait_handler* h(static_cast<wait_handler*>(base)); + typedef handler_alloc_traits<Handler, wait_handler> alloc_traits; + handler_ptr<alloc_traits> ptr(h->handler_, h); + + // Make the upcall if required. + if (owner) + { + // Make a copy of the handler so that the memory can be deallocated + // before the upcall is made. Even if we're not about to make an + // upcall, a sub-object of the handler may be the true owner of the + // memory associated with the handler. Consequently, a local copy of + // the handler is required to ensure that any owning sub-object remains + // valid until after we have deallocated the memory here. + detail::binder1<Handler, boost::system::error_code> + handler(h->handler_, h->ec_); + ptr.reset(); + boost::asio::detail::fenced_block b; + boost_asio_handler_invoke_helpers::invoke(handler, handler); + } } private: - boost::asio::io_service& io_service_; - boost::asio::io_service::work work_; + Handler handler_; }; // Start an asynchronous wait on the timer. template <typename Handler> void async_wait(implementation_type& impl, Handler handler) { + // Allocate and construct an operation to wrap the handler. + typedef wait_handler<Handler> value_type; + typedef handler_alloc_traits<Handler, value_type> alloc_traits; + raw_handler_ptr<alloc_traits> raw_ptr(handler); + handler_ptr<alloc_traits> ptr(raw_ptr, handler); + impl.might_have_pending_waits = true; - scheduler_.schedule_timer(timer_queue_, impl.expiry, - wait_handler<Handler>(this->get_io_service(), handler), &impl); + + scheduler_.schedule_timer(timer_queue_, impl.expiry, ptr.get(), &impl); + ptr.release(); } private: @@ -191,7 +212,7 @@ private: timer_queue<Time_Traits> timer_queue_; // The object that schedules and executes timers. Usually a reactor. - Timer_Scheduler& scheduler_; + timer_scheduler& scheduler_; }; } // namespace detail |