Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84875 - in trunk/boost/asio: . impl
From: chris_at_[hidden]
Date: 2013-06-22 08:44:53


Author: chris_kohlhoff
Date: 2013-06-22 08:44:53 EDT (Sat, 22 Jun 2013)
New Revision: 84875
URL: http://svn.boost.org/trac/boost/changeset/84875

Log:
Add support for both boost.coroutine v1 and v2.

Text files modified:
   trunk/boost/asio/impl/spawn.hpp | 20 ++++++++++----------
   trunk/boost/asio/spawn.hpp | 40 +++++++++++++++++++++++++++++++++++-----
   2 files changed, 45 insertions(+), 15 deletions(-)

Modified: trunk/boost/asio/impl/spawn.hpp
==============================================================================
--- trunk/boost/asio/impl/spawn.hpp Sat Jun 22 08:31:58 2013 (r84874)
+++ trunk/boost/asio/impl/spawn.hpp 2013-06-22 08:44:53 EDT (Sat, 22 Jun 2013) (r84875)
@@ -58,8 +58,8 @@
     }
 
   //private:
- detail::shared_ptr<boost::coroutines::coroutine<void()> > coro_;
- boost::coroutines::coroutine<void()>::caller_type& ca_;
+ shared_ptr<typename basic_yield_context<Handler>::callee_type> coro_;
+ typename basic_yield_context<Handler>::caller_type& ca_;
     Handler& handler_;
     boost::system::error_code* ec_;
     T* value_;
@@ -90,8 +90,8 @@
     }
 
   //private:
- detail::shared_ptr<boost::coroutines::coroutine<void()> > coro_;
- boost::coroutines::coroutine<void()>::caller_type& ca_;
+ shared_ptr<typename basic_yield_context<Handler>::callee_type> coro_;
+ typename basic_yield_context<Handler>::caller_type& ca_;
     Handler& handler_;
     boost::system::error_code* ec_;
   };
@@ -186,7 +186,7 @@
   }
 
 private:
- boost::coroutines::coroutine<void()>::caller_type& ca_;
+ typename basic_yield_context<Handler>::caller_type& ca_;
   boost::system::error_code* out_ec_;
   boost::system::error_code ec_;
   type value_;
@@ -212,7 +212,7 @@
   }
 
 private:
- boost::coroutines::coroutine<void()>::caller_type& ca_;
+ typename basic_yield_context<Handler>::caller_type& ca_;
   boost::system::error_code* out_ec_;
   boost::system::error_code ec_;
 };
@@ -230,7 +230,7 @@
     {
     }
 
- weak_ptr<boost::coroutines::coroutine<void()> > coro_;
+ weak_ptr<typename basic_yield_context<Handler>::callee_type> coro_;
     Handler handler_;
     bool call_handler_;
     Function function_;
@@ -239,7 +239,7 @@
   template <typename Handler, typename Function>
   struct coro_entry_point
   {
- void operator()(boost::coroutines::coroutine<void()>::caller_type& ca)
+ void operator()(typename basic_yield_context<Handler>::caller_type& ca)
     {
       shared_ptr<spawn_data<Handler, Function> > data(data_);
       ca(); // Yield until coroutine pointer has been initialised.
@@ -258,9 +258,9 @@
   {
     void operator()()
     {
+ typedef typename basic_yield_context<Handler>::callee_type callee_type;
       coro_entry_point<Handler, Function> entry_point = { data_ };
- shared_ptr<boost::coroutines::coroutine<void()> > coro(
- new boost::coroutines::coroutine<void()>(entry_point, attributes_));
+ shared_ptr<callee_type> coro(new callee_type(entry_point, attributes_));
       data_->coro_ = coro;
       (*coro)();
     }

Modified: trunk/boost/asio/spawn.hpp
==============================================================================
--- trunk/boost/asio/spawn.hpp Sat Jun 22 08:31:58 2013 (r84874)
+++ trunk/boost/asio/spawn.hpp 2013-06-22 08:44:53 EDT (Sat, 22 Jun 2013) (r84875)
@@ -49,6 +49,36 @@
 class basic_yield_context
 {
 public:
+ /// The coroutine callee type, used by the implementation.
+ /**
+ * When using Boost.Coroutine v1, this type is:
+ * @code typename coroutine<void()> @endcode
+ * When using Boost.Coroutine v2 (unidirectional coroutines), this type is:
+ * @code push_coroutine<void> @endcode
+ */
+#if defined(GENERATING_DOCUMENTATION)
+ typedef implementation_defined callee_type;
+#elif defined(BOOST_COROUTINES_UNIDRECT) || defined(BOOST_COROUTINES_V2)
+ typedef boost::coroutines::push_coroutine<void> callee_type;
+#else
+ typedef boost::coroutines::coroutine<void()> callee_type;
+#endif
+
+ /// The coroutine caller type, used by the implementation.
+ /**
+ * When using Boost.Coroutine v1, this type is:
+ * @code typename coroutine<void()>::caller_type @endcode
+ * When using Boost.Coroutine v2 (unidirectional coroutines), this type is:
+ * @code pull_coroutine<void> @endcode
+ */
+#if defined(GENERATING_DOCUMENTATION)
+ typedef implementation_defined caller_type;
+#elif defined(BOOST_COROUTINES_UNIDRECT) || defined(BOOST_COROUTINES_V2)
+ typedef boost::coroutines::pull_coroutine<void> caller_type;
+#else
+ typedef boost::coroutines::coroutine<void()>::caller_type caller_type;
+#endif
+
   /// Construct a yield context to represent the specified coroutine.
   /**
    * Most applications do not need to use this constructor. Instead, the
@@ -56,8 +86,8 @@
    * function.
    */
   basic_yield_context(
- const detail::weak_ptr<boost::coroutines::coroutine<void()> >& coro,
- boost::coroutines::coroutine<void()>::caller_type& ca, Handler& handler)
+ const detail::weak_ptr<callee_type>& coro,
+ caller_type& ca, Handler& handler)
     : coro_(coro),
       ca_(ca),
       handler_(handler),
@@ -84,7 +114,7 @@
    * ...
    * } @endcode
    */
- basic_yield_context operator[](boost::system::error_code& ec)
+ basic_yield_context operator[](boost::system::error_code& ec) const
   {
     basic_yield_context tmp(*this);
     tmp.ec_ = &ec;
@@ -94,8 +124,8 @@
 #if defined(GENERATING_DOCUMENTATION)
 private:
 #endif // defined(GENERATING_DOCUMENTATION)
- detail::weak_ptr<boost::coroutines::coroutine<void()> > coro_;
- boost::coroutines::coroutine<void()>::caller_type& ca_;
+ detail::weak_ptr<callee_type> coro_;
+ caller_type& ca_;
   Handler& handler_;
   boost::system::error_code* ec_;
 };


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk