BVB Source Codes

mars Show fixedsize_stack.hpp Source code

Return Download mars: download fixedsize_stack.hpp Source code - Download mars Source code - Type:.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 mars_boost {} namespace boost = mars_boost; namespace mars_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.         BOOST_ASSERT( traits_type::minimum_size() <= size_);
  43.         BOOST_ASSERT( traits_type::is_unbounded() || ( traits_type::maximum_size() >= size_) );
  44.     }
  45.  
  46.     stack_context allocate() {
  47.         void * vp = std::malloc( size_);
  48.         if ( ! vp) throw std::bad_alloc();
  49.  
  50.         stack_context sctx;
  51.         sctx.size = size_;
  52.         sctx.sp = static_cast< char * >( vp) + sctx.size;
  53. #if defined(BOOST_USE_VALGRIND)
  54.         sctx.valgrind_stack_id = VALGRIND_STACK_REGISTER( sctx.sp, vp);
  55. #endif
  56.         return sctx;
  57.     }
  58.  
  59.     void deallocate( stack_context & sctx) BOOST_NOEXCEPT_OR_NOTHROW {
  60.         BOOST_ASSERT( sctx.sp);
  61.         BOOST_ASSERT( traits_type::minimum_size() <= sctx.size);
  62.         BOOST_ASSERT( traits_type::is_unbounded() || ( traits_type::maximum_size() >= sctx.size) );
  63.  
  64. #if defined(BOOST_USE_VALGRIND)
  65.         VALGRIND_STACK_DEREGISTER( sctx.valgrind_stack_id);
  66. #endif
  67.         void * vp = static_cast< char * >( sctx.sp) - sctx.size;
  68.         std::free( vp);
  69.     }
  70. };
  71.  
  72. typedef basic_fixedsize_stack< stack_traits >  fixedsize_stack;
  73. # if ! defined(BOOST_USE_SEGMENTED_STACKS)
  74. typedef fixedsize_stack default_stack;
  75. # endif
  76.  
  77. }}
  78.  
  79. #ifdef BOOST_HAS_ABI_HEADERS
  80. #  include BOOST_ABI_SUFFIX
  81. #endif
  82.  
  83. #endif // BOOST_CONTEXT_FIXEDSIZE_H
  84.  
downloadfixedsize_stack.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top