Cease dependence on Thread

On C++11 static local variables are initialized in thread-safe manner, but even on C++03 it should not be a problem because in our case variables are of trivial types, which means double initialization is not an issue, and they are initialized with the same value in every thread.
This commit is contained in:
Nikita Kniazev
2021-06-12 18:40:34 +03:00
parent 3537b312f4
commit 28291a877d
4 changed files with 30 additions and 52 deletions

View File

@@ -38,8 +38,6 @@ target_link_libraries(boost_coroutine
Boost::throw_exception
Boost::type_traits
Boost::utility
PRIVATE
Boost::thread
)
target_compile_definitions(boost_coroutine

View File

@@ -11,7 +11,6 @@ import toolset ;
project boost/coroutine
: requirements
<library>/boost/context//boost_context
<library>/boost/thread//boost_thread
<target-os>linux,<toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack
<target-os>linux,<toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack
@@ -39,7 +38,6 @@ lib boost_coroutine
exceptions.cpp
stack_traits_sources
: <link>shared:<library>../../context/build//boost_context
<link>shared:<library>../../thread/build//boost_thread
;
boost-install boost_coroutine ;

View File

@@ -19,7 +19,7 @@ extern "C" {
#include <cmath>
#include <boost/assert.hpp>
#include <boost/thread.hpp>
#include <boost/config.hpp>
#if !defined (SIGSTKSZ)
# define SIGSTKSZ (8 * 1024)
@@ -32,36 +32,27 @@ extern "C" {
namespace {
void pagesize_( std::size_t * size)
{
// conform to POSIX.1-2001
* size = ::sysconf( _SC_PAGESIZE);
}
void stacksize_limit_( rlimit * limit)
{
// conforming to POSIX.1-2001
#if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
::getrlimit( RLIMIT_STACK, limit);
#else
const int result = ::getrlimit( RLIMIT_STACK, limit);
BOOST_ASSERT( 0 == result);
#endif
}
std::size_t pagesize()
{
static std::size_t size = 0;
static boost::once_flag flag;
boost::call_once( flag, pagesize_, & size);
return size;
// conform to POSIX.1-2001
return ::sysconf( _SC_PAGESIZE);
}
rlimit stacksize_limit()
rlim_t stacksize_limit_()
{
static rlimit limit;
static boost::once_flag flag;
boost::call_once( flag, stacksize_limit_, & limit);
rlimit limit;
// conforming to POSIX.1-2001
#if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
::getrlimit( RLIMIT_STACK, & limit);
#else
const int result = ::getrlimit( RLIMIT_STACK, & limit);
BOOST_ASSERT( 0 == result);
#endif
return limit.rlim_max;
}
rlim_t stacksize_limit() BOOST_NOEXCEPT_OR_NOTHROW {
static rlim_t limit = stacksize_limit_();
return limit;
}
@@ -72,11 +63,14 @@ namespace coroutines {
bool
stack_traits::is_unbounded() BOOST_NOEXCEPT
{ return RLIM_INFINITY == stacksize_limit().rlim_max; }
{ return RLIM_INFINITY == stacksize_limit(); }
std::size_t
stack_traits::page_size() BOOST_NOEXCEPT
{ return pagesize(); }
{
static std::size_t size = pagesize();
return size;
}
std::size_t
stack_traits::default_size() BOOST_NOEXCEPT
@@ -98,7 +92,7 @@ std::size_t
stack_traits::maximum_size() BOOST_NOEXCEPT
{
BOOST_ASSERT( ! is_unbounded() );
return static_cast< std::size_t >( stacksize_limit().rlim_max);
return static_cast< std::size_t >( stacksize_limit() );
}
}}

View File

@@ -20,7 +20,6 @@ extern "C" {
#include <boost/assert.hpp>
#include <boost/coroutine/detail/config.hpp>
#include <boost/thread.hpp>
#include <boost/coroutine/stack_context.hpp>
@@ -44,25 +43,11 @@ extern "C" {
namespace {
void system_info_( SYSTEM_INFO * si)
{ ::GetSystemInfo( si); }
SYSTEM_INFO system_info()
{
static SYSTEM_INFO si;
static boost::once_flag flag;
boost::call_once( flag, static_cast< void(*)( SYSTEM_INFO *) >( system_info_), & si);
return si;
}
std::size_t pagesize()
{ return static_cast< std::size_t >( system_info().dwPageSize); }
std::size_t page_count( std::size_t stacksize)
{
return static_cast< std::size_t >(
std::floor(
static_cast< float >( stacksize) / pagesize() ) );
SYSTEM_INFO si;
::GetSystemInfo(&si);
return static_cast< std::size_t >( si.dwPageSize );
}
}
@@ -78,7 +63,10 @@ stack_traits::is_unbounded() BOOST_NOEXCEPT
std::size_t
stack_traits::page_size() BOOST_NOEXCEPT
{ return pagesize(); }
{
static std::size_t size = pagesize();
return size;
}
std::size_t
stack_traits::default_size() BOOST_NOEXCEPT