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 2009.
  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/coroutine/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/coroutine/detail/config.hpp>
  23. #include <boost/thread.hpp>
  24.  
  25. #include <boost/coroutine/stack_context.hpp>
  26.  
  27. // x86_64
  28. // test x86_64 before i386 because icc might
  29. // define __i686__ for x86_64 too
  30. #if defined(__x86_64__) || defined(__x86_64) \
  31.     || defined(__amd64__) || defined(__amd64) \
  32.     || defined(_M_X64) || defined(_M_AMD64)
  33.  
  34. // Windows seams not to provide a constant or function
  35. // telling the minimal stacksize
  36. # define MIN_STACKSIZE  8 * 1024
  37. #else
  38. # define MIN_STACKSIZE  4 * 1024
  39. #endif
  40.  
  41. #ifdef BOOST_HAS_ABI_HEADERS
  42. #  include BOOST_ABI_PREFIX
  43. #endif
  44.  
  45. namespace {
  46.  
  47. void system_info_( SYSTEM_INFO * si)
  48. { ::GetSystemInfo( si); }
  49.  
  50. SYSTEM_INFO system_info()
  51. {
  52.     static SYSTEM_INFO si;
  53.     static mars_boost::once_flag flag;
  54.     mars_boost::call_once( flag, static_cast< void(*)( SYSTEM_INFO *) >( system_info_), & si);
  55.     return si;
  56. }
  57.  
  58. std::size_t pagesize()
  59. { return static_cast< std::size_t >( system_info().dwPageSize); }
  60.  
  61. std::size_t page_count( std::size_t stacksize)
  62. {
  63.     return static_cast< std::size_t >(
  64.         std::floor(
  65.             static_cast< float >( stacksize) / pagesize() ) );
  66. }
  67.  
  68. }
  69.  
  70. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  71. namespace coroutines {
  72.  
  73. // Windows seams not to provide a limit for the stacksize
  74. // libcoco uses 32k+4k bytes as minimum
  75. bool
  76. stack_traits::is_unbounded() BOOST_NOEXCEPT
  77. { return true; }
  78.  
  79. std::size_t
  80. stack_traits::page_size() BOOST_NOEXCEPT
  81. { return pagesize(); }
  82.  
  83. std::size_t
  84. stack_traits::default_size() BOOST_NOEXCEPT
  85. {
  86.     std::size_t size = 64 * 1024; // 64 kB
  87.     if ( is_unbounded() )
  88.         return (std::max)( size, minimum_size() );
  89.  
  90.     BOOST_ASSERT( maximum_size() >= minimum_size() );
  91.     return maximum_size() == minimum_size()
  92.         ? minimum_size()
  93.         : ( std::min)( size, maximum_size() );
  94. }
  95.  
  96. // because Windows seams not to provide a limit for minimum stacksize
  97. std::size_t
  98. stack_traits::minimum_size() BOOST_NOEXCEPT
  99. { return MIN_STACKSIZE; }
  100.  
  101. // because Windows seams not to provide a limit for maximum stacksize
  102. // maximum_size() can never be called (pre-condition ! is_unbounded() )
  103. std::size_t
  104. stack_traits::maximum_size() BOOST_NOEXCEPT
  105. {
  106.     BOOST_ASSERT( ! is_unbounded() );
  107.     return  1 * 1024 * 1024 * 1024; // 1GB
  108. }
  109.  
  110. }}
  111.  
  112. #ifdef BOOST_HAS_ABI_HEADERS
  113. #  include BOOST_ABI_SUFFIX
  114. #endif
  115.  
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