From baf9a558681bb0cd258a780923e5077a36b28b73 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Wed, 10 Jun 2015 20:52:14 +0200 Subject: [PATCH] enable algiment of control structures on stack --- include/boost/fiber/fiber.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/boost/fiber/fiber.hpp b/include/boost/fiber/fiber.hpp index 44aaafee..480daf33 100644 --- a/include/boost/fiber/fiber.hpp +++ b/include/boost/fiber/fiber.hpp @@ -44,9 +44,22 @@ private: template< typename StackAlloc, typename Fn, typename ... Args > static ptr_t create( StackAlloc salloc, Fn && fn, Args && ... args) { context::stack_context sctx( salloc.allocate() ); +#if defined(BOOST_NO_CXX14_CONSTEXPR) || defined(BOOST_NO_CXX11_STD_ALIGN) // reserve space for control structure std::size_t size = sctx.size - sizeof( fiber_context); void * sp = static_cast< char * >( sctx.sp) - sizeof( fiber_context); +#else + constexpr std::size_t func_alignment = 64; // alignof( fiber_context); + constexpr std::size_t func_size = sizeof( fiber_context); + // reserve space on stack + void * sp = static_cast< char * >( sctx.sp) - func_size - func_alignment; + // align sp pointer + std::size_t space = func_size + func_alignment; + sp = std::align( func_alignment, func_size, sp, space); + BOOST_ASSERT( nullptr != sp); + // calculate remaining size + std::size_t size = sctx.size - ( static_cast< char * >( sctx.sp) - static_cast< char * >( sp) ); +#endif // placement new of fiber_context on top of fiber's stack return ptr_t( new ( sp) fiber_context( context::preallocated( sp, size, sctx), salloc,