BVB Source Codes

mars Show pull_coroutine_object.hpp Source code

Return Download mars: download pull_coroutine_object.hpp Source code - Download mars Source code - Type:.hpp
  1.  
  2. //          Copyright Oliver Kowalke 2009.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. //    (See accompanying file LICENSE_1_0.txt or copy at
  5. //          http://www.boost.org/LICENSE_1_0.txt)
  6.  
  7. #ifndef BOOST_COROUTINES_DETAIL_PULL_COROUTINE_OBJECT_H
  8. #define BOOST_COROUTINES_DETAIL_PULL_COROUTINE_OBJECT_H
  9.  
  10. #include <boost/assert.hpp>
  11. #include <boost/config.hpp>
  12. #include <boost/cstdint.hpp>
  13. #include <boost/exception_ptr.hpp>
  14. #include <boost/move/move.hpp>
  15.  
  16. #include <boost/coroutine/detail/config.hpp>
  17. #include <boost/coroutine/detail/coroutine_context.hpp>
  18. #include <boost/coroutine/detail/flags.hpp>
  19. #include <boost/coroutine/detail/preallocated.hpp>
  20. #include <boost/coroutine/detail/pull_coroutine_impl.hpp>
  21. #include <boost/coroutine/detail/trampoline_pull.hpp>
  22. #include <boost/coroutine/exceptions.hpp>
  23. #include <boost/coroutine/flags.hpp>
  24. #include <boost/coroutine/stack_context.hpp>
  25. #include <boost/detail/no_exceptions_support.hpp>
  26.  
  27. #ifdef BOOST_HAS_ABI_HEADERS
  28. #  include BOOST_ABI_PREFIX
  29. #endif
  30.  
  31. #if defined(BOOST_MSVC)
  32. # pragma warning(push)
  33. # pragma warning(disable:4355)
  34. #endif
  35.  
  36. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  37. namespace coroutines {
  38. namespace detail {
  39.  
  40. struct pull_coroutine_context
  41. {
  42.     coroutine_context   caller;
  43.     coroutine_context   callee;
  44.  
  45.     template< typename Coro >
  46.     pull_coroutine_context( preallocated const& palloc, Coro *) :
  47.         caller(),
  48.         callee( trampoline_pull< Coro >, palloc)
  49.     {}
  50. };
  51.  
  52. template< typename PushCoro, typename R, typename Fn, typename StackAllocator >
  53. class pull_coroutine_object : private pull_coroutine_context,
  54.                               public pull_coroutine_impl< R >
  55. {
  56. private:
  57.     typedef pull_coroutine_context                                      ctx_t;
  58.     typedef pull_coroutine_impl< R >                                    base_t;
  59.     typedef pull_coroutine_object< PushCoro, R, Fn, StackAllocator >    obj_t;
  60.  
  61.     Fn                  fn_;
  62.     stack_context       stack_ctx_;
  63.     StackAllocator      stack_alloc_;
  64.  
  65.     static void deallocate_( obj_t * obj)
  66.     {
  67.         stack_context stack_ctx( obj->stack_ctx_);
  68.         StackAllocator stack_alloc( obj->stack_alloc_);
  69.         obj->unwind_stack();
  70.         obj->~obj_t();
  71.         stack_alloc.deallocate( stack_ctx);
  72.     }
  73.  
  74. public:
  75. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  76.     pull_coroutine_object( Fn fn, attributes const& attrs,
  77.                            preallocated const& palloc,
  78.                            StackAllocator const& stack_alloc) BOOST_NOEXCEPT :
  79.         ctx_t( palloc, this),
  80.         base_t( & this->caller,
  81.                 & this->callee,
  82.                 stack_unwind == attrs.do_unwind),
  83.         fn_( fn),
  84.         stack_ctx_( palloc.sctx),
  85.         stack_alloc_( stack_alloc)
  86.     {}
  87. #endif
  88.  
  89.     pull_coroutine_object( BOOST_RV_REF( Fn) fn, attributes const& attrs,
  90.                            preallocated const& palloc,
  91.                            StackAllocator const& stack_alloc) BOOST_NOEXCEPT :
  92.         ctx_t( palloc, this),
  93.         base_t( & this->caller,
  94.                 & this->callee,
  95.                 stack_unwind == attrs.do_unwind),
  96. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  97.         fn_( fn),
  98. #else
  99.         fn_( mars_boost::forward< Fn >( fn) ),
  100. #endif
  101.         stack_ctx_( palloc.sctx),
  102.         stack_alloc_( stack_alloc)
  103.     {}
  104.  
  105.     void run()
  106.     {
  107.         BOOST_ASSERT( ! base_t::unwind_requested() );
  108.  
  109.         base_t::flags_ |= flag_started;
  110.         base_t::flags_ |= flag_running;
  111.  
  112.         // create push_coroutine
  113.         typename PushCoro::synth_type b( & this->callee, & this->caller, false);
  114.         PushCoro push_coro( synthesized_t::syntesized, b);
  115.         BOOST_TRY
  116.         { fn_( push_coro); }
  117.         BOOST_CATCH ( forced_unwind const&)
  118.         {}
  119.         BOOST_CATCH (...)
  120.         { base_t::except_ = current_exception(); }BOOST_CATCH_END
  121.  
  122.         base_t::flags_ |= flag_complete;
  123.         base_t::flags_ &= ~flag_running;
  124.         typename base_t::param_type to;
  125.         this->callee.jump(
  126.             this->caller,
  127.             & to);
  128.         BOOST_ASSERT_MSG( false, "pull_coroutine is complete");
  129.     }
  130.  
  131.     void destroy() { deallocate_( this); }
  132. };
  133.  
  134. template< typename PushCoro, typename R, typename Fn, typename StackAllocator >
  135. class pull_coroutine_object< PushCoro, R&, Fn, StackAllocator > : private pull_coroutine_context,
  136.                                                                    public pull_coroutine_impl< R & >
  137. {
  138. private:
  139.     typedef pull_coroutine_context                                      ctx_t;
  140.     typedef pull_coroutine_impl< R & >                                  base_t;
  141.     typedef pull_coroutine_object< PushCoro, R &, Fn, StackAllocator >  obj_t;
  142.  
  143.     Fn                  fn_;
  144.     stack_context       stack_ctx_;
  145.     StackAllocator      stack_alloc_;
  146.  
  147.     static void deallocate_( obj_t * obj)
  148.     {
  149.         stack_context stack_ctx( obj->stack_ctx_);
  150.         StackAllocator stack_alloc( obj->stack_alloc_);
  151.         obj->unwind_stack();
  152.         obj->~obj_t();
  153.         stack_alloc.deallocate( stack_ctx);
  154.     }
  155.  
  156. public:
  157. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  158.     pull_coroutine_object( Fn fn, attributes const& attrs,
  159.                            preallocated const& palloc,
  160.                            StackAllocator const& stack_alloc) BOOST_NOEXCEPT :
  161.         ctx_t( palloc, this),
  162.         base_t( & this->caller,
  163.                 & this->callee,
  164.                 stack_unwind == attrs.do_unwind),
  165.         fn_( fn),
  166.         stack_ctx_( palloc.sctx),
  167.         stack_alloc_( stack_alloc)
  168.     {}
  169. #endif
  170.  
  171.     pull_coroutine_object( BOOST_RV_REF( Fn) fn, attributes const& attrs,
  172.                            preallocated const& palloc,
  173.                            StackAllocator const& stack_alloc) BOOST_NOEXCEPT :
  174.         ctx_t( palloc, this),
  175.         base_t( & this->caller,
  176.                 & this->callee,
  177.                 stack_unwind == attrs.do_unwind),
  178. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  179.         fn_( fn),
  180. #else
  181.         fn_( mars_boost::forward< Fn >( fn) ),
  182. #endif
  183.         stack_ctx_( palloc.sctx),
  184.         stack_alloc_( stack_alloc)
  185.     {}
  186.  
  187.     void run()
  188.     {
  189.         BOOST_ASSERT( ! base_t::unwind_requested() );
  190.  
  191.         base_t::flags_ |= flag_started;
  192.         base_t::flags_ |= flag_running;
  193.  
  194.         // create push_coroutine
  195.         typename PushCoro::synth_type b( & this->callee, & this->caller, false);
  196.         PushCoro push_coro( synthesized_t::syntesized, b);
  197.         BOOST_TRY
  198.         { fn_( push_coro); }
  199.         BOOST_CATCH ( forced_unwind const&)
  200.         {}
  201.         BOOST_CATCH (...)
  202.         { base_t::except_ = current_exception(); }BOOST_CATCH_END
  203.  
  204.         base_t::flags_ |= flag_complete;
  205.         base_t::flags_ &= ~flag_running;
  206.         typename base_t::param_type to;
  207.         this->callee.jump(
  208.             this->caller,
  209.             & to);
  210.         BOOST_ASSERT_MSG( false, "pull_coroutine is complete");
  211.     }
  212.  
  213.     void destroy()
  214.     { deallocate_( this); }
  215. };
  216.  
  217. template< typename PushCoro, typename Fn, typename StackAllocator >
  218. class pull_coroutine_object< PushCoro, void, Fn, StackAllocator > : private pull_coroutine_context,
  219.                                                                     public pull_coroutine_impl< void >
  220. {
  221. private:
  222.     typedef pull_coroutine_context                                      ctx_t;
  223.     typedef pull_coroutine_impl< void >                                 base_t;
  224.     typedef pull_coroutine_object< PushCoro, void, Fn, StackAllocator > obj_t;
  225.  
  226.     Fn                  fn_;
  227.     stack_context       stack_ctx_;
  228.     StackAllocator      stack_alloc_;
  229.  
  230.     static void deallocate_( obj_t * obj)
  231.     {
  232.         stack_context stack_ctx( obj->stack_ctx_);
  233.         StackAllocator stack_alloc( obj->stack_alloc_);
  234.         obj->unwind_stack();
  235.         obj->~obj_t();
  236.         stack_alloc.deallocate( stack_ctx);
  237.     }
  238.  
  239. public:
  240. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  241.     pull_coroutine_object( Fn fn, attributes const& attrs,
  242.                            preallocated const& palloc,
  243.                            StackAllocator const& stack_alloc) BOOST_NOEXCEPT :
  244.         ctx_t( palloc, this),
  245.         base_t( & this->caller,
  246.                 & this->callee,
  247.                 stack_unwind == attrs.do_unwind),
  248.         fn_( fn),
  249.         stack_ctx_( palloc.sctx),
  250.         stack_alloc_( stack_alloc)
  251.     {}
  252. #endif
  253.  
  254.     pull_coroutine_object( BOOST_RV_REF( Fn) fn, attributes const& attrs,
  255.                            preallocated const& palloc,
  256.                            StackAllocator const& stack_alloc) BOOST_NOEXCEPT :
  257.         ctx_t( palloc, this),
  258.         base_t( & this->caller,
  259.                 & this->callee,
  260.                 stack_unwind == attrs.do_unwind),
  261. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  262.         fn_( fn),
  263. #else
  264.         fn_( mars_boost::forward< Fn >( fn) ),
  265. #endif
  266.         stack_ctx_( palloc.sctx),
  267.         stack_alloc_( stack_alloc)
  268.     {}
  269.  
  270.     void run()
  271.     {
  272.         BOOST_ASSERT( ! base_t::unwind_requested() );
  273.  
  274.         base_t::flags_ |= flag_started;
  275.         base_t::flags_ |= flag_running;
  276.  
  277.         // create push_coroutine
  278.         typename PushCoro::synth_type b( & this->callee, & this->caller, false);
  279.         PushCoro push_coro( synthesized_t::syntesized, b);
  280.         BOOST_TRY
  281.         { fn_( push_coro); }
  282.         BOOST_CATCH ( forced_unwind const&)
  283.         {}
  284.         BOOST_CATCH (...)
  285.         { base_t::except_ = current_exception(); }BOOST_CATCH_END
  286.  
  287.         base_t::flags_ |= flag_complete;
  288.         base_t::flags_ &= ~flag_running;
  289.         typename base_t::param_type to;
  290.         this->callee.jump(
  291.             this->caller,
  292.             & to);
  293.         BOOST_ASSERT_MSG( false, "pull_coroutine is complete");
  294.     }
  295.  
  296.     void destroy()
  297.     { deallocate_( this); }
  298. };
  299.  
  300. }}}
  301.  
  302. #if defined(BOOST_MSVC)
  303. # pragma warning(pop)
  304. #endif
  305.  
  306. #ifdef BOOST_HAS_ABI_HEADERS
  307. #  include BOOST_ABI_SUFFIX
  308. #endif
  309.  
  310. #endif // BOOST_COROUTINES_DETAIL_PULL_COROUTINE_OBJECT_H
  311.  
downloadpull_coroutine_object.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top