trampoline.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_TRAMPOLINE_H
  6. #define BOOST_COROUTINES_DETAIL_TRAMPOLINE_H
  7. #include <boost/assert.hpp>
  8. #include <boost/config.hpp>
  9. #include <boost/context/detail/fcontext.hpp>
  10. #include <boost/cstdint.hpp>
  11. #include <boost/coroutine/detail/config.hpp>
  12. #include <boost/coroutine/detail/data.hpp>
  13. #ifdef BOOST_HAS_ABI_HEADERS
  14. # include BOOST_ABI_PREFIX
  15. #endif
  16. namespace boost {
  17. namespace coroutines {
  18. namespace detail {
  19. template< typename Coro >
  20. void trampoline( context::detail::transfer_t t)
  21. {
  22. typedef typename Coro::param_type param_type;
  23. data_t * data = static_cast< data_t * >( t.data);
  24. data->from->ctx_ = t.fctx;
  25. param_type * param(
  26. static_cast< param_type * >( data->data) );
  27. BOOST_ASSERT( 0 != param);
  28. BOOST_ASSERT( 0 != param->data);
  29. Coro * coro(
  30. static_cast< Coro * >( param->coro) );
  31. BOOST_ASSERT( 0 != coro);
  32. coro->run( param->data);
  33. }
  34. template< typename Coro >
  35. void trampoline_void( context::detail::transfer_t t)
  36. {
  37. typedef typename Coro::param_type param_type;
  38. data_t * data = static_cast< data_t * >( t.data);
  39. data->from->ctx_ = t.fctx;
  40. param_type * param(
  41. static_cast< param_type * >( data->data) );
  42. BOOST_ASSERT( 0 != param);
  43. Coro * coro(
  44. static_cast< Coro * >( param->coro) );
  45. BOOST_ASSERT( 0 != coro);
  46. coro->run();
  47. }
  48. }}}
  49. #ifdef BOOST_HAS_ABI_HEADERS
  50. # include BOOST_ABI_SUFFIX
  51. #endif
  52. #endif // BOOST_COROUTINES_DETAIL_TRAMPOLINE_H