File indexing completed on 2025-01-18 09:30:32
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_COROUTINES_SEGMENTED_STACK_ALLOCATOR_H
0008 #define BOOST_COROUTINES_SEGMENTED_STACK_ALLOCATOR_H
0009
0010 #include <cstddef>
0011 #include <new>
0012
0013 #include <boost/config.hpp>
0014
0015 #include <boost/coroutine/detail/config.hpp>
0016 #include <boost/coroutine/stack_context.hpp>
0017 #include <boost/coroutine/stack_traits.hpp>
0018
0019 #ifdef BOOST_HAS_ABI_HEADERS
0020 # include BOOST_ABI_PREFIX
0021 #endif
0022
0023
0024 extern "C" {
0025 void *__splitstack_makecontext( std::size_t,
0026 void * [BOOST_CONTEXT_SEGMENTS],
0027 std::size_t *);
0028
0029 void __splitstack_releasecontext( void * [BOOST_CONTEXT_SEGMENTS]);
0030
0031 void __splitstack_resetcontext( void * [BOOST_CONTEXT_SEGMENTS]);
0032
0033 void __splitstack_block_signals_context( void * [BOOST_CONTEXT_SEGMENTS],
0034 int * new_value, int * old_value);
0035 }
0036
0037 namespace boost {
0038 namespace coroutines {
0039
0040 template< typename traitsT >
0041 struct basic_segmented_stack_allocator
0042 {
0043 typedef traitsT traits_type;
0044
0045 void allocate( stack_context & ctx, std::size_t size = traits_type::minimum_size() )
0046 {
0047 void * limit = __splitstack_makecontext( size, ctx.segments_ctx, & ctx.size);
0048 if ( ! limit) throw std::bad_alloc();
0049
0050
0051 ctx.sp = static_cast< char * >( limit) + ctx.size;
0052
0053 int off = 0;
0054 __splitstack_block_signals_context( ctx.segments_ctx, & off, 0);
0055 }
0056
0057 void deallocate( stack_context & ctx)
0058 { __splitstack_releasecontext( ctx.segments_ctx); }
0059 };
0060
0061 typedef basic_segmented_stack_allocator< stack_traits > segmented_stack_allocator;
0062
0063 }}
0064
0065 #ifdef BOOST_HAS_ABI_HEADERS
0066 # include BOOST_ABI_SUFFIX
0067 #endif
0068
0069 #endif