pull_control_block_cc.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright Oliver Kowalke 2016.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_HPP
  6. #define BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_HPP
  7. #include <exception>
  8. #include <type_traits>
  9. #include <boost/config.hpp>
  10. #include <boost/context/fiber.hpp>
  11. #include <boost/coroutine2/detail/state.hpp>
  12. #ifdef BOOST_HAS_ABI_HEADERS
  13. # include BOOST_ABI_PREFIX
  14. #endif
  15. namespace boost {
  16. namespace coroutines2 {
  17. namespace detail {
  18. template< typename T >
  19. struct pull_coroutine< T >::control_block {
  20. boost::context::fiber c;
  21. typename push_coroutine< T >::control_block * other;
  22. state_t state;
  23. std::exception_ptr except;
  24. bool bvalid;
  25. typename std::aligned_storage< sizeof( T), alignof( T) >::type storage;
  26. static void destroy( control_block * cb) noexcept;
  27. template< typename StackAllocator, typename Fn >
  28. control_block( context::preallocated, StackAllocator &&, Fn &&);
  29. control_block( typename push_coroutine< T >::control_block *, boost::context::fiber &) noexcept;
  30. ~control_block();
  31. control_block( control_block &) = delete;
  32. control_block & operator=( control_block &) = delete;
  33. void deallocate() noexcept;
  34. void resume();
  35. void set( T const&);
  36. void set( T &&);
  37. T & get() noexcept;
  38. bool valid() const noexcept;
  39. };
  40. template< typename T >
  41. struct pull_coroutine< T & >::control_block {
  42. struct holder {
  43. T & t;
  44. holder( T & t_) :
  45. t{ t_ } {
  46. }
  47. };
  48. boost::context::fiber c;
  49. typename push_coroutine< T & >::control_block * other;
  50. state_t state;
  51. std::exception_ptr except;
  52. bool bvalid;
  53. typename std::aligned_storage< sizeof( holder), alignof( holder) >::type storage;
  54. static void destroy( control_block * cb) noexcept;
  55. template< typename StackAllocator, typename Fn >
  56. control_block( context::preallocated, StackAllocator &&, Fn &&);
  57. control_block( typename push_coroutine< T & >::control_block *, boost::context::fiber &) noexcept;
  58. control_block( control_block &) = delete;
  59. control_block & operator=( control_block &) = delete;
  60. void deallocate() noexcept;
  61. void resume();
  62. void set( T &);
  63. T & get() noexcept;
  64. bool valid() const noexcept;
  65. };
  66. struct pull_coroutine< void >::control_block {
  67. boost::context::fiber c;
  68. push_coroutine< void >::control_block * other;
  69. state_t state;
  70. std::exception_ptr except;
  71. static void destroy( control_block * cb) noexcept;
  72. template< typename StackAllocator, typename Fn >
  73. control_block( context::preallocated, StackAllocator &&, Fn &&);
  74. control_block( push_coroutine< void >::control_block *, boost::context::fiber &) noexcept;
  75. control_block( control_block &) = delete;
  76. control_block & operator=( control_block &) = delete;
  77. void deallocate() noexcept;
  78. void resume();
  79. bool valid() const noexcept;
  80. };
  81. }}}
  82. #ifdef BOOST_HAS_ABI_HEADERS
  83. # include BOOST_ABI_SUFFIX
  84. #endif
  85. #endif // BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_HPP