diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-03-21 15:45:20 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-03-21 15:46:37 +0900 |
commit | 733b5d5ae2c5d625211e2985ac25728ac3f54883 (patch) | |
tree | a5b214744b256f07e1dc2bd7273035a7808c659f /boost/context/posix/segmented_stack.hpp | |
parent | 08c1e93fa36a49f49325a07fe91ff92c964c2b6c (diff) | |
download | boost-upstream/1.58.0.tar.gz boost-upstream/1.58.0.tar.bz2 boost-upstream/1.58.0.zip |
Imported Upstream version 1.58.0upstream/1.58.0
Change-Id: If0072143aa26874812e0db6872e1efb10a3e5e94
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/context/posix/segmented_stack.hpp')
-rw-r--r-- | boost/context/posix/segmented_stack.hpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/boost/context/posix/segmented_stack.hpp b/boost/context/posix/segmented_stack.hpp new file mode 100644 index 0000000000..f4a32d7394 --- /dev/null +++ b/boost/context/posix/segmented_stack.hpp @@ -0,0 +1,81 @@ + +// Copyright Oliver Kowalke 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_CONTEXT_SEGMENTED_H +#define BOOST_CONTEXT_SEGMENTED_H + +#include <cstddef> +#include <new> + +#include <boost/config.hpp> + +#include <boost/context/detail/config.hpp> +#include <boost/context/stack_context.hpp> +#include <boost/context/stack_traits.hpp> + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif + +// forward declaration for splitstack-functions defined in libgcc +extern "C" { +void *__splitstack_makecontext( std::size_t, + void * [BOOST_CONTEXT_SEGMENTS], + std::size_t *); + +void __splitstack_releasecontext( void * [BOOST_CONTEXT_SEGMENTS]); + +void __splitstack_resetcontext( void * [BOOST_CONTEXT_SEGMENTS]); + +void __splitstack_block_signals_context( void * [BOOST_CONTEXT_SEGMENTS], + int * new_value, int * old_value); +} + +namespace boost { +namespace context { + +template< typename traitsT > +class basic_segmented_stack { +private: + std::size_t size_; + +public: + typedef traitsT traits_type; + + basic_segmented_stack( std::size_t size = traits_type::default_size() ) : + size_( size) { + BOOST_ASSERT( traits_type::minimum_size() <= size_); + BOOST_ASSERT( traits_type::is_unbounded() || ( traits_type::maximum_size() >= size_) ); + } + + stack_context allocate() { + stack_context sctx; + void * vp = __splitstack_makecontext( size_, sctx.segments_ctx, & sctx.size); + if ( ! vp) throw std::bad_alloc(); + + // sctx.size is already filled by __splitstack_makecontext + sctx.sp = static_cast< char * >( vp) + sctx.size; + + int off = 0; + __splitstack_block_signals_context( sctx.segments_ctx, & off, 0); + + return sctx; + } + + void deallocate( stack_context & sctx) { + __splitstack_releasecontext( sctx.segments_ctx); + } +}; + +typedef basic_segmented_stack< stack_traits > segmented_stack; + +}} + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif + +#endif // BOOST_CONTEXT_SEGMENTED_H |