trampoline.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 <cstddef>
  8. #include <boost/assert.hpp>
  9. #include <boost/config.hpp>
  10. #include <boost/cstdint.hpp>
  11. #include <boost/tuple/tuple.hpp>
  12. #ifdef BOOST_HAS_ABI_HEADERS
  13. # include BOOST_ABI_PREFIX
  14. #endif
  15. namespace boost {
  16. namespace coroutines {
  17. namespace detail {
  18. template< typename Coroutine >
  19. void trampoline1( intptr_t vp)
  20. {
  21. BOOST_ASSERT( vp);
  22. reinterpret_cast< Coroutine * >( vp)->run();
  23. }
  24. template< typename Coroutine, typename Arg >
  25. void trampoline2( intptr_t vp)
  26. {
  27. BOOST_ASSERT( vp);
  28. tuple< Coroutine *, Arg > * tpl(
  29. reinterpret_cast< tuple< Coroutine *, Arg > * >( vp) );
  30. Coroutine * coro( get< 0 >( * tpl) );
  31. Arg arg( get< 1 >( * tpl) );
  32. coro->run( arg);
  33. }
  34. }}}
  35. #ifdef BOOST_HAS_ABI_HEADERS
  36. # include BOOST_ABI_SUFFIX
  37. #endif
  38. #endif // BOOST_COROUTINES_DETAIL_TRAMPOLINE_H