Skip to content

Commit 9c0e903

Browse files
authored
Merge pull request boostorg#58 from Kojoley/feature/cease-dependence-on-thread
Cease dependence on Thread
2 parents 3537b31 + 28291a8 commit 9c0e903

File tree

4 files changed

+23
-45
lines changed

4 files changed

+23
-45
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ target_link_libraries(boost_coroutine
3838
Boost::throw_exception
3939
Boost::type_traits
4040
Boost::utility
41-
PRIVATE
42-
Boost::thread
4341
)
4442

4543
target_compile_definitions(boost_coroutine

build/Jamfile.v2

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import toolset ;
1111
project boost/coroutine
1212
: requirements
1313
<library>/boost/context//boost_context
14-
<library>/boost/thread//boost_thread
1514
<target-os>linux,<toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack
1615
<target-os>linux,<toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
1716
<toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack
@@ -39,7 +38,6 @@ lib boost_coroutine
3938
exceptions.cpp
4039
stack_traits_sources
4140
: <link>shared:<library>../../context/build//boost_context
42-
<link>shared:<library>../../thread/build//boost_thread
4341
;
4442

4543
boost-install boost_coroutine ;

src/posix/stack_traits.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern "C" {
1919
#include <cmath>
2020

2121
#include <boost/assert.hpp>
22-
#include <boost/thread.hpp>
22+
#include <boost/config.hpp>
2323

2424
#if !defined (SIGSTKSZ)
2525
# define SIGSTKSZ (8 * 1024)
@@ -32,36 +32,27 @@ extern "C" {
3232

3333
namespace {
3434

35-
void pagesize_( std::size_t * size)
35+
std::size_t pagesize()
3636
{
3737
// conform to POSIX.1-2001
38-
* size = ::sysconf( _SC_PAGESIZE);
38+
return ::sysconf( _SC_PAGESIZE);
3939
}
4040

41-
void stacksize_limit_( rlimit * limit)
41+
rlim_t stacksize_limit_()
4242
{
43+
rlimit limit;
4344
// conforming to POSIX.1-2001
4445
#if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
45-
::getrlimit( RLIMIT_STACK, limit);
46+
::getrlimit( RLIMIT_STACK, & limit);
4647
#else
47-
const int result = ::getrlimit( RLIMIT_STACK, limit);
48+
const int result = ::getrlimit( RLIMIT_STACK, & limit);
4849
BOOST_ASSERT( 0 == result);
4950
#endif
51+
return limit.rlim_max;
5052
}
5153

52-
std::size_t pagesize()
53-
{
54-
static std::size_t size = 0;
55-
static boost::once_flag flag;
56-
boost::call_once( flag, pagesize_, & size);
57-
return size;
58-
}
59-
60-
rlimit stacksize_limit()
61-
{
62-
static rlimit limit;
63-
static boost::once_flag flag;
64-
boost::call_once( flag, stacksize_limit_, & limit);
54+
rlim_t stacksize_limit() BOOST_NOEXCEPT_OR_NOTHROW {
55+
static rlim_t limit = stacksize_limit_();
6556
return limit;
6657
}
6758

@@ -72,11 +63,14 @@ namespace coroutines {
7263

7364
bool
7465
stack_traits::is_unbounded() BOOST_NOEXCEPT
75-
{ return RLIM_INFINITY == stacksize_limit().rlim_max; }
66+
{ return RLIM_INFINITY == stacksize_limit(); }
7667

7768
std::size_t
7869
stack_traits::page_size() BOOST_NOEXCEPT
79-
{ return pagesize(); }
70+
{
71+
static std::size_t size = pagesize();
72+
return size;
73+
}
8074

8175
std::size_t
8276
stack_traits::default_size() BOOST_NOEXCEPT
@@ -98,7 +92,7 @@ std::size_t
9892
stack_traits::maximum_size() BOOST_NOEXCEPT
9993
{
10094
BOOST_ASSERT( ! is_unbounded() );
101-
return static_cast< std::size_t >( stacksize_limit().rlim_max);
95+
return static_cast< std::size_t >( stacksize_limit() );
10296
}
10397

10498
}}

src/windows/stack_traits.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ extern "C" {
2020

2121
#include <boost/assert.hpp>
2222
#include <boost/coroutine/detail/config.hpp>
23-
#include <boost/thread.hpp>
2423

2524
#include <boost/coroutine/stack_context.hpp>
2625

@@ -44,25 +43,11 @@ extern "C" {
4443

4544
namespace {
4645

47-
void system_info_( SYSTEM_INFO * si)
48-
{ ::GetSystemInfo( si); }
49-
50-
SYSTEM_INFO system_info()
51-
{
52-
static SYSTEM_INFO si;
53-
static boost::once_flag flag;
54-
boost::call_once( flag, static_cast< void(*)( SYSTEM_INFO *) >( system_info_), & si);
55-
return si;
56-
}
57-
5846
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)
6247
{
63-
return static_cast< std::size_t >(
64-
std::floor(
65-
static_cast< float >( stacksize) / pagesize() ) );
48+
SYSTEM_INFO si;
49+
::GetSystemInfo(&si);
50+
return static_cast< std::size_t >( si.dwPageSize );
6651
}
6752

6853
}
@@ -78,7 +63,10 @@ stack_traits::is_unbounded() BOOST_NOEXCEPT
7863

7964
std::size_t
8065
stack_traits::page_size() BOOST_NOEXCEPT
81-
{ return pagesize(); }
66+
{
67+
static std::size_t size = pagesize();
68+
return size;
69+
}
8270

8371
std::size_t
8472
stack_traits::default_size() BOOST_NOEXCEPT

0 commit comments

Comments
 (0)