summaryrefslogtreecommitdiff
path: root/boost/context/fixedsize_stack.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/context/fixedsize_stack.hpp')
-rw-r--r--boost/context/fixedsize_stack.hpp75
1 files changed, 71 insertions, 4 deletions
diff --git a/boost/context/fixedsize_stack.hpp b/boost/context/fixedsize_stack.hpp
index 46e7866891..756b260bda 100644
--- a/boost/context/fixedsize_stack.hpp
+++ b/boost/context/fixedsize_stack.hpp
@@ -4,10 +4,77 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_CONTEXT_FIXEDSIZE_H
+#define BOOST_CONTEXT_FIXEDSIZE_H
+
+#include <cstddef>
+#include <cstdlib>
+#include <new>
+
+#include <boost/assert.hpp>
#include <boost/config.hpp>
-#if defined(BOOST_WINDOWS)
-# include <boost/context/windows/fixedsize_stack.hpp>
-#else
-# include <boost/context/posix/fixedsize_stack.hpp>
+#include <boost/context/detail/config.hpp>
+#include <boost/context/stack_context.hpp>
+#include <boost/context/stack_traits.hpp>
+
+#if defined(BOOST_USE_VALGRIND)
+#include <valgrind/valgrind.h>
+#endif
+
+#ifdef BOOST_HAS_ABI_HEADERS
+# include BOOST_ABI_PREFIX
#endif
+
+namespace boost {
+namespace context {
+
+template< typename traitsT >
+class basic_fixedsize_stack {
+private:
+ std::size_t size_;
+
+public:
+ typedef traitsT traits_type;
+
+ basic_fixedsize_stack( std::size_t size = traits_type::default_size() ) BOOST_NOEXCEPT_OR_NOTHROW :
+ size_( size) {
+ }
+
+ stack_context allocate() {
+ void * vp = std::malloc( size_);
+ if ( ! vp) {
+ throw std::bad_alloc();
+ }
+ stack_context sctx;
+ sctx.size = size_;
+ sctx.sp = static_cast< char * >( vp) + sctx.size;
+#if defined(BOOST_USE_VALGRIND)
+ sctx.valgrind_stack_id = VALGRIND_STACK_REGISTER( sctx.sp, vp);
+#endif
+ return sctx;
+ }
+
+ void deallocate( stack_context & sctx) BOOST_NOEXCEPT_OR_NOTHROW {
+ BOOST_ASSERT( sctx.sp);
+
+#if defined(BOOST_USE_VALGRIND)
+ VALGRIND_STACK_DEREGISTER( sctx.valgrind_stack_id);
+#endif
+ void * vp = static_cast< char * >( sctx.sp) - sctx.size;
+ std::free( vp);
+ }
+};
+
+typedef basic_fixedsize_stack< stack_traits > fixedsize_stack;
+# if ! defined(BOOST_USE_SEGMENTED_STACKS)
+typedef fixedsize_stack default_stack;
+# endif
+
+}}
+
+#ifdef BOOST_HAS_ABI_HEADERS
+# include BOOST_ABI_SUFFIX
+#endif
+
+#endif // BOOST_CONTEXT_FIXEDSIZE_H