]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/coroutine2/include/boost/coroutine2/detail/create_control_block.ipp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / coroutine2 / include / boost / coroutine2 / detail / create_control_block.ipp
1
2 // Copyright Oliver Kowalke 2014.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifndef BOOST_COROUTINES2_DETAIL_CREATE_CONTROLBLOCK_IPP
8 #define BOOST_COROUTINES2_DETAIL_CREATE_CONTROLBLOCK_IPP
9
10 #include <cstddef>
11 #include <memory>
12 #include <utility>
13
14 #include <boost/assert.hpp>
15 #include <boost/config.hpp>
16
17 #include <boost/context/preallocated.hpp>
18 #include <boost/context/stack_context.hpp>
19
20 #include <boost/coroutine2/detail/config.hpp>
21
22 #ifdef BOOST_HAS_ABI_HEADERS
23 # include BOOST_ABI_PREFIX
24 #endif
25
26 namespace boost {
27 namespace coroutines2 {
28 namespace detail {
29
30 template< typename ControlBlock, typename StackAllocator, typename Fn >
31 ControlBlock * create_control_block( StackAllocator salloc, Fn && fn) {
32 auto sctx = salloc.allocate();
33 // reserve space for control structure
34 #if defined(BOOST_NO_CXX11_CONSTEXPR) || defined(BOOST_NO_CXX11_STD_ALIGN)
35 void * sp = static_cast< char * >( sctx.sp) - sizeof( ControlBlock);
36 const std::size_t size = sctx.size - sizeof( ControlBlock);
37 #else
38 constexpr std::size_t func_alignment = 64; // alignof( ControlBlock);
39 constexpr std::size_t func_size = sizeof( ControlBlock);
40 // reserve space on stack
41 void * sp = static_cast< char * >( sctx.sp) - func_size - func_alignment;
42 // align sp pointer
43 std::size_t space = func_size + func_alignment;
44 sp = std::align( func_alignment, func_size, sp, space);
45 BOOST_ASSERT( nullptr != sp);
46 // calculate remaining size
47 const std::size_t size = sctx.size - ( static_cast< char * >( sctx.sp) - static_cast< char * >( sp) );
48 #endif
49 // placment new for control structure on coroutine stack
50 return new ( sp) ControlBlock{ context::preallocated( sp, size, sctx),
51 salloc, std::forward< Fn >( fn) };
52 }
53
54 }}}
55
56 #ifdef BOOST_HAS_ABI_HEADERS
57 # include BOOST_ABI_SUFFIX
58 #endif
59
60 #endif // BOOST_COROUTINES2_DETAIL_CREATE_CONTROLBLOCK_IPP