BVB Source Codes

mars Show stack_traits.cpp Source code

Return Download mars: download stack_traits.cpp Source code - Download mars Source code - Type:.cpp
  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. #include "boost/context/stack_traits.hpp"
  8.  
  9. extern "C" {
  10. #include <windows.h>
  11. }
  12.  
  13. //#if defined (BOOST_WINDOWS) || _POSIX_C_SOURCE >= 200112L
  14.  
  15. #include <algorithm>
  16. #include <cmath>
  17. #include <cstddef>
  18. #include <cstring>
  19. #include <stdexcept>
  20.  
  21. #include <boost/assert.hpp>
  22. #include <boost/context/detail/config.hpp>
  23. #if defined(BOOST_NO_CXX11_HDR_MUTEX)
  24. # include <boost/thread.hpp>
  25. #else
  26. # include <mutex>
  27. #endif
  28.  
  29. #include <boost/context/stack_context.hpp>
  30.  
  31. // x86_64
  32. // test x86_64 before i386 because icc might
  33. // define __i686__ for x86_64 too
  34. #if defined(__x86_64__) || defined(__x86_64) \
  35.     || defined(__amd64__) || defined(__amd64) \
  36.     || defined(_M_X64) || defined(_M_AMD64)
  37.  
  38. // Windows seams not to provide a constant or function
  39. // telling the minimal stacksize
  40. # define MIN_STACKSIZE  8 * 1024
  41. #else
  42. # define MIN_STACKSIZE  4 * 1024
  43. #endif
  44.  
  45. #ifdef BOOST_HAS_ABI_HEADERS
  46. #  include BOOST_ABI_PREFIX
  47. #endif
  48.  
  49. namespace {
  50.  
  51. void system_info_( SYSTEM_INFO * si) BOOST_NOEXCEPT_OR_NOTHROW {
  52.     ::GetSystemInfo( si);
  53. }
  54.  
  55. SYSTEM_INFO system_info() BOOST_NOEXCEPT_OR_NOTHROW {
  56.     static SYSTEM_INFO si;
  57. #if defined(BOOST_NO_CXX11_HDR_MUTEX)
  58.     static mars_boost::once_flag flag = BOOST_ONCE_INIT;
  59.     mars_boost::call_once( flag, static_cast< void(*)( SYSTEM_INFO *) >( system_info_), & si);
  60. #else
  61.     static std::once_flag flag;
  62.     std::call_once( flag, static_cast< void(*)( SYSTEM_INFO *) >( system_info_), & si);
  63. #endif
  64.     return si;
  65. }
  66.  
  67. std::size_t pagesize() BOOST_NOEXCEPT_OR_NOTHROW {
  68.     return static_cast< std::size_t >( system_info().dwPageSize);
  69. }
  70.  
  71. std::size_t page_count( std::size_t stacksize) BOOST_NOEXCEPT_OR_NOTHROW {
  72.     return static_cast< std::size_t >(
  73.         std::floor(
  74.             static_cast< float >( stacksize) / pagesize() ) );
  75. }
  76.  
  77. }
  78.  
  79. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  80. namespace context {
  81.  
  82. // Windows seams not to provide a limit for the stacksize
  83. // libcoco uses 32k+4k bytes as minimum
  84. BOOST_CONTEXT_DECL
  85. bool
  86. stack_traits::is_unbounded() BOOST_NOEXCEPT_OR_NOTHROW {
  87.     return true;
  88. }
  89.  
  90. BOOST_CONTEXT_DECL
  91. std::size_t
  92. stack_traits::page_size() BOOST_NOEXCEPT_OR_NOTHROW {
  93.     return pagesize();
  94. }
  95.  
  96. BOOST_CONTEXT_DECL
  97. std::size_t
  98. stack_traits::default_size() BOOST_NOEXCEPT_OR_NOTHROW {
  99.     const std::size_t size = 64 * 1024; // 64 kB
  100.     if ( is_unbounded() ) {
  101.         return (std::max)( size, minimum_size() );
  102.     }
  103.     BOOST_ASSERT( maximum_size() >= minimum_size() );
  104.     return maximum_size() == minimum_size()
  105.         ? minimum_size()
  106.         : ( std::min)( size, maximum_size() );
  107. }
  108.  
  109. // because Windows seams not to provide a limit for minimum stacksize
  110. BOOST_CONTEXT_DECL
  111. std::size_t
  112. stack_traits::minimum_size() BOOST_NOEXCEPT_OR_NOTHROW {
  113.     return MIN_STACKSIZE;
  114. }
  115.  
  116. // because Windows seams not to provide a limit for maximum stacksize
  117. // maximum_size() can never be called (pre-condition ! is_unbounded() )
  118. BOOST_CONTEXT_DECL
  119. std::size_t
  120. stack_traits::maximum_size() BOOST_NOEXCEPT_OR_NOTHROW {
  121.     BOOST_ASSERT( ! is_unbounded() );
  122.     return  1 * 1024 * 1024 * 1024; // 1GB
  123. }
  124.  
  125. }}
  126.  
  127. #ifdef BOOST_HAS_ABI_HEADERS
  128. #  include BOOST_ABI_SUFFIX
  129. #endif
  130.  
downloadstack_traits.cpp 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