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)
7 #ifndef BOOST_CONTEXT_FIXEDSIZE_H
8 #define BOOST_CONTEXT_FIXEDSIZE_H
14 #include <boost/assert.hpp>
15 #include <boost/config.hpp>
17 #include <boost/context/detail/config.hpp>
18 #include <boost/context/stack_context.hpp>
19 #include <boost/context/stack_traits.hpp>
21 #if defined(BOOST_USE_VALGRIND)
22 #include <valgrind/valgrind.h>
25 #ifdef BOOST_HAS_ABI_HEADERS
26 # include BOOST_ABI_PREFIX
32 template< typename traitsT >
33 class basic_fixedsize_stack {
38 typedef traitsT traits_type;
40 basic_fixedsize_stack( std::size_t size = traits_type::default_size() ) BOOST_NOEXCEPT_OR_NOTHROW :
44 stack_context allocate() {
45 void * vp = std::malloc( size_);
47 throw std::bad_alloc();
51 sctx.sp = static_cast< char * >( vp) + sctx.size;
52 #if defined(BOOST_USE_VALGRIND)
53 sctx.valgrind_stack_id = VALGRIND_STACK_REGISTER( sctx.sp, vp);
58 void deallocate( stack_context & sctx) BOOST_NOEXCEPT_OR_NOTHROW {
59 BOOST_ASSERT( sctx.sp);
61 #if defined(BOOST_USE_VALGRIND)
62 VALGRIND_STACK_DEREGISTER( sctx.valgrind_stack_id);
64 void * vp = static_cast< char * >( sctx.sp) - sctx.size;
69 typedef basic_fixedsize_stack< stack_traits > fixedsize_stack;
70 # if ! defined(BOOST_USE_SEGMENTED_STACKS)
71 typedef fixedsize_stack default_stack;
76 #ifdef BOOST_HAS_ABI_HEADERS
77 # include BOOST_ABI_SUFFIX
80 #endif // BOOST_CONTEXT_FIXEDSIZE_H