File indexing completed on 2025-01-18 09:30:33
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_COROUTINES2_DETAIL_CREATE_CONTROLBLOCK_IPP
0008 #define BOOST_COROUTINES2_DETAIL_CREATE_CONTROLBLOCK_IPP
0009
0010 #include <cstddef>
0011 #include <memory>
0012 #include <utility>
0013
0014 #include <boost/assert.hpp>
0015 #include <boost/config.hpp>
0016
0017 #include <boost/context/preallocated.hpp>
0018 #include <boost/context/stack_context.hpp>
0019
0020 #include <boost/coroutine2/detail/config.hpp>
0021
0022 #ifdef BOOST_HAS_ABI_HEADERS
0023 # include BOOST_ABI_PREFIX
0024 #endif
0025
0026 namespace boost {
0027 namespace coroutines2 {
0028 namespace detail {
0029
0030 template< typename ControlBlock, typename StackAllocator, typename Fn >
0031 ControlBlock * create_control_block( StackAllocator && salloc, Fn && fn) {
0032 auto sctx = salloc.allocate();
0033
0034 #if defined(BOOST_NO_CXX11_CONSTEXPR) || defined(BOOST_NO_CXX11_STD_ALIGN)
0035 void * sp = static_cast< char * >( sctx.sp) - sizeof( ControlBlock);
0036 const std::size_t size = sctx.size - sizeof( ControlBlock);
0037 #else
0038 constexpr std::size_t func_alignment = 64;
0039 constexpr std::size_t func_size = sizeof( ControlBlock);
0040
0041 void * sp = static_cast< char * >( sctx.sp) - func_size - func_alignment;
0042
0043 std::size_t space = func_size + func_alignment;
0044 sp = std::align( func_alignment, func_size, sp, space);
0045 BOOST_ASSERT( nullptr != sp);
0046
0047 const std::size_t size = sctx.size - ( static_cast< char * >( sctx.sp) - static_cast< char * >( sp) );
0048 #endif
0049
0050 return new ( sp) ControlBlock{ context::preallocated( sp, size, sctx),
0051 std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) };
0052 }
0053
0054 }}}
0055
0056 #ifdef BOOST_HAS_ABI_HEADERS
0057 # include BOOST_ABI_SUFFIX
0058 #endif
0059
0060 #endif