Skip to content

Cease dependence on Thread #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions build/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ;
38 changes: 16 additions & 22 deletions src/posix/stack_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -32,36 +32,27 @@ extern "C" {

namespace {

void pagesize_( std::size_t * size)
std::size_t pagesize()
{
// conform to POSIX.1-2001
* size = ::sysconf( _SC_PAGESIZE);
return ::sysconf( _SC_PAGESIZE);
}

void stacksize_limit_( rlimit * limit)
rlim_t stacksize_limit_()
{
rlimit limit;
// conforming to POSIX.1-2001
#if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
::getrlimit( RLIMIT_STACK, limit);
::getrlimit( RLIMIT_STACK, & limit);
#else
const int result = ::getrlimit( RLIMIT_STACK, limit);
const int result = ::getrlimit( RLIMIT_STACK, & limit);
BOOST_ASSERT( 0 == result);
#endif
return limit.rlim_max;
}

std::size_t pagesize()
{
static std::size_t size = 0;
static boost::once_flag flag;
boost::call_once( flag, pagesize_, & size);
return size;
}

rlimit stacksize_limit()
{
static rlimit limit;
static boost::once_flag flag;
boost::call_once( flag, stacksize_limit_, & limit);
rlim_t stacksize_limit() BOOST_NOEXCEPT_OR_NOTHROW {
static rlim_t limit = stacksize_limit_();
return limit;
}

Expand All @@ -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
Expand All @@ -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() );
}

}}
Expand Down
26 changes: 7 additions & 19 deletions src/windows/stack_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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 );
}

}
Expand All @@ -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
Expand Down