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 <signal.h>
  11. #include <sys/resource.h>
  12. #include <sys/time.h>
  13. #include <unistd.h>
  14. }
  15.  
  16. //#if _POSIX_C_SOURCE >= 200112L
  17.  
  18. #include <algorithm>
  19. #include <cmath>
  20.  
  21. #include <boost/assert.hpp>
  22. #include <boost/thread.hpp>
  23.  
  24. #if !defined (SIGSTKSZ)
  25. # define SIGSTKSZ (8 * 1024)
  26. # define UDEF_SIGSTKSZ
  27. #endif
  28.  
  29. #ifdef BOOST_HAS_ABI_HEADERS
  30. #  include BOOST_ABI_PREFIX
  31. #endif
  32.  
  33. namespace {
  34.  
  35. void pagesize_( std::size_t * size)
  36. {
  37.     // conform to POSIX.1-2001
  38.     * size = ::sysconf( _SC_PAGESIZE);
  39. }
  40.  
  41. void stacksize_limit_( rlimit * limit)
  42. {
  43.     // conforming to POSIX.1-2001
  44. #if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
  45.     ::getrlimit( RLIMIT_STACK, limit);
  46. #else
  47.     const int result = ::getrlimit( RLIMIT_STACK, limit);
  48.     BOOST_ASSERT( 0 == result);
  49. #endif
  50. }
  51.  
  52. std::size_t pagesize()
  53. {
  54.     static std::size_t size = 0;
  55.     static mars_boost::once_flag flag;
  56.     mars_boost::call_once( flag, pagesize_, & size);
  57.     return size;
  58. }
  59.  
  60. rlimit stacksize_limit()
  61. {
  62.     static rlimit limit;
  63.     static mars_boost::once_flag flag;
  64.     mars_boost::call_once( flag, stacksize_limit_, & limit);
  65.     return limit;
  66. }
  67.  
  68. }
  69.  
  70. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  71. namespace coroutines {
  72.  
  73. bool
  74. stack_traits::is_unbounded() BOOST_NOEXCEPT
  75. { return RLIM_INFINITY == stacksize_limit().rlim_max; }
  76.  
  77. std::size_t
  78. stack_traits::page_size() BOOST_NOEXCEPT
  79. { return pagesize(); }
  80.  
  81. std::size_t
  82. stack_traits::default_size() BOOST_NOEXCEPT
  83. {
  84.     std::size_t size = 8 * minimum_size();
  85.     if ( is_unbounded() ) return size;
  86.  
  87.     BOOST_ASSERT( maximum_size() >= minimum_size() );
  88.     return maximum_size() == size
  89.         ? size
  90.         : (std::min)( size, maximum_size() );
  91. }
  92.  
  93. std::size_t
  94. stack_traits::minimum_size() BOOST_NOEXCEPT
  95. { return SIGSTKSZ; }
  96.  
  97. std::size_t
  98. stack_traits::maximum_size() BOOST_NOEXCEPT
  99. {
  100.     BOOST_ASSERT( ! is_unbounded() );
  101.     return static_cast< std::size_t >( stacksize_limit().rlim_max);
  102. }
  103.  
  104. }}
  105.  
  106. #ifdef BOOST_HAS_ABI_HEADERS
  107. #  include BOOST_ABI_SUFFIX
  108. #endif
  109.  
  110. #ifdef UDEF_SIGSTKSZ
  111. # undef SIGSTKSZ
  112. #endif
  113.  
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