coroutine_context.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright Oliver Kowalke 2009.
  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_COROUTINES_DETAIL_COROUTINE_CONTEXT_H
  6. #define BOOST_COROUTINES_DETAIL_COROUTINE_CONTEXT_H
  7. #include <cstddef>
  8. #include <boost/assert.hpp>
  9. #include <boost/config.hpp>
  10. #include <boost/context/detail/fcontext.hpp>
  11. #include <boost/coroutine/detail/config.hpp>
  12. #include <boost/coroutine/detail/preallocated.hpp>
  13. #include <boost/coroutine/stack_context.hpp>
  14. #ifdef BOOST_HAS_ABI_HEADERS
  15. # include BOOST_ABI_PREFIX
  16. #endif
  17. namespace boost {
  18. namespace coroutines {
  19. namespace detail {
  20. // class hold stack-context and coroutines execution-context
  21. class BOOST_COROUTINES_DECL coroutine_context
  22. {
  23. private:
  24. template< typename Coro >
  25. friend void trampoline( context::detail::transfer_t);
  26. template< typename Coro >
  27. friend void trampoline_void( context::detail::transfer_t);
  28. template< typename Coro >
  29. friend void trampoline_pull( context::detail::transfer_t);
  30. template< typename Coro >
  31. friend void trampoline_push( context::detail::transfer_t);
  32. template< typename Coro >
  33. friend void trampoline_push_void( context::detail::transfer_t);
  34. preallocated palloc_;
  35. context::detail::fcontext_t ctx_;
  36. public:
  37. typedef void( * ctx_fn)( context::detail::transfer_t);
  38. // default ctor represents the current execution-context
  39. coroutine_context();
  40. // ctor creates a new execution-context running coroutine-fn `fn`
  41. // `ctx_` will be allocated on top of the stack managed by parameter
  42. // `stack_ctx`
  43. coroutine_context( ctx_fn fn, preallocated const& palloc);
  44. coroutine_context( coroutine_context const&);
  45. coroutine_context& operator=( coroutine_context const&);
  46. void * jump( coroutine_context &, void * = 0);
  47. stack_context & stack_ctx()
  48. { return palloc_.sctx; }
  49. };
  50. }}}
  51. #ifdef BOOST_HAS_ABI_HEADERS
  52. # include BOOST_ABI_SUFFIX
  53. #endif
  54. #endif // BOOST_COROUTINES_DETAIL_COROUTINE_CONTEXT_H