]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/context/fixedsize_stack.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / context / fixedsize_stack.hpp
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
21 #if defined(BOOST_USE_VALGRIND)
22 #include <valgrind/valgrind.h>
23 #endif
24
25 #ifdef BOOST_HAS_ABI_HEADERS
26 # include BOOST_ABI_PREFIX
27 #endif
28
29 namespace boost {
30 namespace context {
31
32 template< typename traitsT >
33 class basic_fixedsize_stack {
34 private:
35 std::size_t size_;
36
37 public:
38 typedef traitsT traits_type;
39
40 basic_fixedsize_stack( std::size_t size = traits_type::default_size() ) BOOST_NOEXCEPT_OR_NOTHROW :
41 size_( size) {
42 }
43
44 stack_context allocate() {
45 void * vp = std::malloc( size_);
46 if ( ! vp) {
47 throw std::bad_alloc();
48 }
49 stack_context sctx;
50 sctx.size = size_;
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);
54 #endif
55 return sctx;
56 }
57
58 void deallocate( stack_context & sctx) BOOST_NOEXCEPT_OR_NOTHROW {
59 BOOST_ASSERT( sctx.sp);
60
61 #if defined(BOOST_USE_VALGRIND)
62 VALGRIND_STACK_DEREGISTER( sctx.valgrind_stack_id);
63 #endif
64 void * vp = static_cast< char * >( sctx.sp) - sctx.size;
65 std::free( vp);
66 }
67 };
68
69 typedef basic_fixedsize_stack< stack_traits > fixedsize_stack;
70 # if ! defined(BOOST_USE_SEGMENTED_STACKS)
71 typedef fixedsize_stack default_stack;
72 # endif
73
74 }}
75
76 #ifdef BOOST_HAS_ABI_HEADERS
77 # include BOOST_ABI_SUFFIX
78 #endif
79
80 #endif // BOOST_CONTEXT_FIXEDSIZE_H