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 <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/config.hpp>
  23. #if defined(BOOST_NO_CXX11_HDR_MUTEX)
  24. # include <boost/thread.hpp>
  25. #else
  26. # include <mutex>
  27. #endif
  28.  
  29. #if !defined (SIGSTKSZ)
  30. # define SIGSTKSZ (8 * 1024)
  31. # define UDEF_SIGSTKSZ
  32. #endif
  33.  
  34. #ifdef BOOST_HAS_ABI_HEADERS
  35. #  include BOOST_ABI_PREFIX
  36. #endif
  37.  
  38. namespace {
  39.  
  40. void pagesize_( std::size_t * size) BOOST_NOEXCEPT_OR_NOTHROW {
  41.     // conform to POSIX.1-2001
  42.     * size = ::sysconf( _SC_PAGESIZE);
  43. }
  44.  
  45. void stacksize_limit_( rlimit * limit) BOOST_NOEXCEPT_OR_NOTHROW {
  46.     // conforming to POSIX.1-2001
  47.     ::getrlimit( RLIMIT_STACK, limit);
  48. }
  49.  
  50. std::size_t pagesize() BOOST_NOEXCEPT_OR_NOTHROW {
  51.     static std::size_t size = 0;
  52. #if defined(BOOST_NO_CXX11_HDR_MUTEX)
  53.     static mars_boost::once_flag flag = BOOST_ONCE_INIT;
  54.     mars_boost::call_once( flag, pagesize_, &size);
  55. #else
  56.     static std::once_flag flag;
  57.     std::call_once( flag, pagesize_, &size);
  58. #endif
  59.     return size;
  60. }
  61.  
  62. rlimit stacksize_limit() BOOST_NOEXCEPT_OR_NOTHROW {
  63.     static rlimit limit;
  64. #if defined(BOOST_NO_CXX11_HDR_MUTEX)
  65.     static mars_boost::once_flag flag = BOOST_ONCE_INIT;
  66.     mars_boost::call_once( flag, stacksize_limit_, &limit);
  67. #else
  68.     static std::once_flag flag;
  69.     std::call_once( flag, stacksize_limit_, &limit);
  70. #endif
  71.     return limit;
  72. }
  73.  
  74. }
  75.  
  76. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  77. namespace context {
  78.  
  79. bool
  80. stack_traits::is_unbounded() BOOST_NOEXCEPT_OR_NOTHROW {
  81.     return RLIM_INFINITY == stacksize_limit().rlim_max;
  82. }
  83.  
  84. std::size_t
  85. stack_traits::page_size() BOOST_NOEXCEPT_OR_NOTHROW {
  86.     return pagesize();
  87. }
  88.  
  89. std::size_t
  90. stack_traits::default_size() BOOST_NOEXCEPT_OR_NOTHROW {
  91.     std::size_t size = 8 * minimum_size();
  92.     if ( is_unbounded() ) {
  93.         return size;
  94.     }
  95.  
  96.     BOOST_ASSERT( maximum_size() >= minimum_size() );
  97.     return maximum_size() == size
  98.         ? size
  99.         : (std::min)( size, maximum_size() );
  100. }
  101.  
  102. std::size_t
  103. stack_traits::minimum_size() BOOST_NOEXCEPT_OR_NOTHROW {
  104.     return SIGSTKSZ;
  105. }
  106.  
  107. std::size_t
  108. stack_traits::maximum_size() BOOST_NOEXCEPT_OR_NOTHROW {
  109.     BOOST_ASSERT( ! is_unbounded() );
  110.     return static_cast< std::size_t >( stacksize_limit().rlim_max);
  111. }
  112.  
  113. }}
  114.  
  115. #ifdef BOOST_HAS_ABI_HEADERS
  116. #  include BOOST_ABI_SUFFIX
  117. #endif
  118.  
  119. #ifdef UDEF_SIGSTKSZ
  120. # undef SIGSTKSZ
  121. #endif
  122.  
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