]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/context/fixedsize_stack.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / context / fixedsize_stack.hpp
CommitLineData
7c673cae
FG
1
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)
6
7#ifndef BOOST_CONTEXT_FIXEDSIZE_H
8#define BOOST_CONTEXT_FIXEDSIZE_H
9
10#include <cstddef>
11#include <cstdlib>
12#include <new>
13
14#include <boost/assert.hpp>
15#include <boost/config.hpp>
16
17#include <boost/context/detail/config.hpp>
18#include <boost/context/stack_context.hpp>
19#include <boost/context/stack_traits.hpp>
20
92f5a8d4
TL
21#if defined(BOOST_CONTEXT_USE_MAP_STACK)
22extern "C" {
23#include <sys/mman.h>
24}
25#endif
26
7c673cae
FG
27#if defined(BOOST_USE_VALGRIND)
28#include <valgrind/valgrind.h>
29#endif
30
31#ifdef BOOST_HAS_ABI_HEADERS
32# include BOOST_ABI_PREFIX
33#endif
34
35namespace boost {
36namespace context {
37
38template< typename traitsT >
39class basic_fixedsize_stack {
40private:
41 std::size_t size_;
42
43public:
44 typedef traitsT traits_type;
45
46 basic_fixedsize_stack( std::size_t size = traits_type::default_size() ) BOOST_NOEXCEPT_OR_NOTHROW :
47 size_( size) {
7c673cae
FG
48 }
49
50 stack_context allocate() {
92f5a8d4
TL
51#if defined(BOOST_CONTEXT_USE_MAP_STACK)
52 void * vp = ::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_STACK, -1, 0);
53 if ( vp == MAP_FAILED) {
54 throw std::bad_alloc();
55 }
56#else
7c673cae
FG
57 void * vp = std::malloc( size_);
58 if ( ! vp) {
59 throw std::bad_alloc();
60 }
92f5a8d4 61#endif
7c673cae
FG
62 stack_context sctx;
63 sctx.size = size_;
64 sctx.sp = static_cast< char * >( vp) + sctx.size;
65#if defined(BOOST_USE_VALGRIND)
66 sctx.valgrind_stack_id = VALGRIND_STACK_REGISTER( sctx.sp, vp);
67#endif
68 return sctx;
69 }
70
71 void deallocate( stack_context & sctx) BOOST_NOEXCEPT_OR_NOTHROW {
72 BOOST_ASSERT( sctx.sp);
7c673cae
FG
73
74#if defined(BOOST_USE_VALGRIND)
75 VALGRIND_STACK_DEREGISTER( sctx.valgrind_stack_id);
76#endif
77 void * vp = static_cast< char * >( sctx.sp) - sctx.size;
92f5a8d4
TL
78#if defined(BOOST_CONTEXT_USE_MAP_STACK)
79 ::munmap( vp, sctx.size);
80#else
7c673cae 81 std::free( vp);
92f5a8d4 82#endif
7c673cae
FG
83 }
84};
85
86typedef basic_fixedsize_stack< stack_traits > fixedsize_stack;
87# if ! defined(BOOST_USE_SEGMENTED_STACKS)
88typedef fixedsize_stack default_stack;
89# endif
90
91}}
92
93#ifdef BOOST_HAS_ABI_HEADERS
94# include BOOST_ABI_SUFFIX
95#endif
96
97#endif // BOOST_CONTEXT_FIXEDSIZE_H