$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: chris_at_[hidden]
Date: 2007-09-01 02:28:55
Author: chris_kohlhoff
Date: 2007-09-01 02:28:40 EDT (Sat, 01 Sep 2007)
New Revision: 39096
URL: http://svn.boost.org/trac/boost/changeset/39096
Log:
Ensure that a strand is kept alive as long as there are wrapped handlers
for it.
Text files modified: 
   trunk/boost/asio/detail/strand_service.hpp  |     8 ++++----                                
   trunk/boost/asio/detail/wrapped_handler.hpp |    14 ++++++++++----                          
   trunk/boost/asio/impl/io_service.ipp        |     4 ++--                                    
   trunk/boost/asio/io_service.hpp             |     2 +-                                      
   4 files changed, 17 insertions(+), 11 deletions(-)
Modified: trunk/boost/asio/detail/strand_service.hpp
==============================================================================
--- trunk/boost/asio/detail/strand_service.hpp	(original)
+++ trunk/boost/asio/detail/strand_service.hpp	2007-09-01 02:28:40 EDT (Sat, 01 Sep 2007)
@@ -417,14 +417,14 @@
     }
     else
     {
-      boost::asio::detail::mutex::scoped_lock lock(impl->mutex_);
-
       // Allocate and construct an object to wrap the handler.
       typedef handler_wrapper<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);
 
+      boost::asio::detail::mutex::scoped_lock lock(impl->mutex_);
+
       if (impl->current_handler_ == 0)
       {
         // This handler now has the lock, so can be dispatched immediately.
@@ -457,14 +457,14 @@
   template <typename Handler>
   void post(implementation_type& impl, Handler handler)
   {
-    boost::asio::detail::mutex::scoped_lock lock(impl->mutex_);
-
     // Allocate and construct an object to wrap the handler.
     typedef handler_wrapper<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);
 
+    boost::asio::detail::mutex::scoped_lock lock(impl->mutex_);
+
     if (impl->current_handler_ == 0)
     {
       // This handler now has the lock, so can be dispatched immediately.
Modified: trunk/boost/asio/detail/wrapped_handler.hpp
==============================================================================
--- trunk/boost/asio/detail/wrapped_handler.hpp	(original)
+++ trunk/boost/asio/detail/wrapped_handler.hpp	2007-09-01 02:28:40 EDT (Sat, 01 Sep 2007)
@@ -17,6 +17,10 @@
 
 #include <boost/asio/detail/push_options.hpp>
 
+#include <boost/asio/detail/push_options.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/asio/detail/pop_options.hpp>
+
 #include <boost/asio/detail/bind_handler.hpp>
 #include <boost/asio/detail/handler_alloc_helpers.hpp>
 #include <boost/asio/detail/handler_invoke_helpers.hpp>
@@ -31,7 +35,9 @@
 public:
   typedef void result_type;
 
-  wrapped_handler(Dispatcher& dispatcher, Handler handler)
+  wrapped_handler(
+      typename boost::add_reference<Dispatcher>::type dispatcher,
+      Handler handler)
     : dispatcher_(dispatcher),
       handler_(handler)
   {
@@ -118,7 +124,7 @@
   }
 
 //private:
-  Dispatcher& dispatcher_;
+  Dispatcher dispatcher_;
   Handler handler_;
 };
 
@@ -172,9 +178,9 @@
         function, this_handler->handler_));
 }
 
-template <typename Function, typename Dispatcher, typename Handler>
+template <typename Function, typename Handler, typename Context>
 inline void asio_handler_invoke(const Function& function,
-    rewrapped_handler<Dispatcher, Handler>* this_handler)
+    rewrapped_handler<Handler, Context>* this_handler)
 {
   asio_handler_invoke_helpers::invoke(
       function, &this_handler->context_);
Modified: trunk/boost/asio/impl/io_service.ipp
==============================================================================
--- trunk/boost/asio/impl/io_service.ipp	(original)
+++ trunk/boost/asio/impl/io_service.ipp	2007-09-01 02:28:40 EDT (Sat, 01 Sep 2007)
@@ -129,11 +129,11 @@
 #if defined(GENERATING_DOCUMENTATION)
 unspecified
 #else
-inline detail::wrapped_handler<io_service, Handler>
+inline detail::wrapped_handler<io_service&, Handler>
 #endif
 io_service::wrap(Handler handler)
 {
-  return detail::wrapped_handler<io_service, Handler>(*this, handler);
+  return detail::wrapped_handler<io_service&, Handler>(*this, handler);
 }
 
 inline io_service::work::work(boost::asio::io_service& io_service)
Modified: trunk/boost/asio/io_service.hpp
==============================================================================
--- trunk/boost/asio/io_service.hpp	(original)
+++ trunk/boost/asio/io_service.hpp	2007-09-01 02:28:40 EDT (Sat, 01 Sep 2007)
@@ -321,7 +321,7 @@
 #if defined(GENERATING_DOCUMENTATION)
   unspecified
 #else
-  detail::wrapped_handler<io_service, Handler>
+  detail::wrapped_handler<io_service&, Handler>
 #endif
   wrap(Handler handler);