diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index a4d358c..889f28b 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -19,17 +19,13 @@ feature.compose on : BOOST_USE_SEGMENTED_STACKS ; project boost/context : requirements - /boost/system//boost_system /boost/thread//boost_thread - SOLARIS:_XOPEN_SOURCE=600 - gcc-4.7,on:-fsplit-stack - gcc-4.7,on:"-static-libgcc" - gcc-4.8,on:-fsplit-stack - gcc-4.8,on:"-static-libgcc" - gcc-4.9,on:-fsplit-stack - gcc-4.9,on:"-static-libgcc" - clang-3.4,on:-fsplit-stack - clang-3.4,on:"-static-libgcc" + gcc,on:-fsplit-stack + gcc,on:-DBOOST_USE_SEGMENTED_STACKS + gcc,on:"-static-libgcc" + clang,on:-fsplit-stack + clang,on:-DBOOST_USE_SEGMENTED_STACKS + clang,on:"-static-libgcc" shared:BOOST_CONTEXT_DYN_LINK=1 BOOST_CONTEXT_SOURCE multi diff --git a/example/execution_context/Jamfile.v2 b/example/execution_context/Jamfile.v2 index 5153265..5810d6f 100644 --- a/example/execution_context/Jamfile.v2 +++ b/example/execution_context/Jamfile.v2 @@ -15,18 +15,13 @@ import os ; import toolset ; import architecture ; -project boost/econtext/example +project boost/context/example/execution_context : requirements /boost/context//boost_context - /boost/thread//boost_thread - gcc-4.7,on:-fsplit-stack - gcc-4.7,on:-DBOOST_USE_SEGMENTED_STACKS - gcc-4.8,on:-fsplit-stack - gcc-4.8,on:-DBOOST_USE_SEGMENTED_STACKS - gcc-4.9,on:-fsplit-stack - gcc-4.9,on:-DBOOST_USE_SEGMENTED_STACKS - clang-3.4,on:-fsplit-stack - clang-3.4,on:-DBOOST_USE_SEGMENTED_STACKS + gcc,on:-fsplit-stack + gcc,on:-DBOOST_USE_SEGMENTED_STACKS + clang,on:-fsplit-stack + clang,on:-DBOOST_USE_SEGMENTED_STACKS static multi ; diff --git a/example/execution_context/jump.cpp b/example/execution_context/jump.cpp index c0a3d6b..01baa87 100644 --- a/example/execution_context/jump.cpp +++ b/example/execution_context/jump.cpp @@ -5,14 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include #include -#include - -#include -#include -#include +#include boost::context::execution_context * ctx1 = nullptr; boost::context::execution_context * ctx2 = nullptr; @@ -33,10 +28,10 @@ void f2() { ctx->jump_to(); } -int main( int argc, char * argv[]) { - boost::context::execution_context ctx1_( boost::context::fixedsize(), f1, 3); +int main() { + boost::context::execution_context ctx1_( boost::context::fixedsize_stack(), f1, 3); ctx1 = & ctx1_; - boost::context::execution_context ctx2_( boost::context::protected_fixedsize(), f2); + boost::context::execution_context ctx2_( boost::context::protected_fixedsize_stack(), f2); ctx2 = & ctx2_; boost::context::execution_context ctx_( boost::context::execution_context::current() ); ctx = & ctx_; diff --git a/example/execution_context/parser.cpp b/example/execution_context/parser.cpp index 4457e4f..ad2ba4a 100644 --- a/example/execution_context/parser.cpp +++ b/example/execution_context/parser.cpp @@ -4,14 +4,12 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include +#include #include #include #include -#include -#include -#include +#include /* * grammar: @@ -87,16 +85,17 @@ private: } }; -void foo() { +int main() { std::istringstream is("1+1"); bool done=false; char c; + + // invert control flow boost::context::execution_context main_ctx( boost::context::execution_context::current() ); - // invert control flow boost::context::execution_context parser_ctx( - boost::context::fixedsize(), - [&is,&main_ctx,&done,&c](){ + boost::context::fixedsize_stack(), + [&main_ctx,&is,&c,&done](){ Parser p(is,[&main_ctx,&c](char ch){ c=ch; main_ctx.jump_to(); @@ -107,14 +106,13 @@ void foo() { }); // user-code pulls parsed data from parser - while(!done){ - parser_ctx.jump_to(); + parser_ctx.jump_to(); + do { printf("Parsed: %c\n",c); - } -} + parser_ctx.jump_to(); + } while( ! done); -int main() { - std::thread t( foo); - t.join(); - return 0; + std::cout << "main: done" << std::endl; + + return EXIT_SUCCESS; } diff --git a/example/execution_context/segmented.cpp b/example/execution_context/segmented.cpp index 81a6925..f076f48 100644 --- a/example/execution_context/segmented.cpp +++ b/example/execution_context/segmented.cpp @@ -4,14 +4,12 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#include #include -#include #include -#include -#include -#include +#include #ifdef BOOST_MSVC //MS VisualStudio __declspec(noinline) void access( char *buf); @@ -35,16 +33,16 @@ void bar( int i) } } -int main( int argc, char * argv[]) { +int main() { int count = 384; #if defined(BOOST_USE_SEGMENTED_STACKS) - std::cout << "using segmented stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; - std::cout << "initial stack size = " << boost::context::segmented::traits_type::default_size() / 1024 << "kB" << std::endl; + std::cout << "using segmented_stack stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; + std::cout << "initial stack size = " << boost::context::segmented_stack::traits_type::default_size() / 1024 << "kB" << std::endl; std::cout << "application should not fail" << std::endl; #else std::cout << "using standard stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; - std::cout << "initial stack size = " << boost::context::fixedsize::traits_type::default_size() / 1024 << "kB" << std::endl; + std::cout << "initial stack size = " << boost::context::fixedsize_stack::traits_type::default_size() / 1024 << "kB" << std::endl; std::cout << "application might fail" << std::endl; #endif @@ -53,9 +51,9 @@ int main( int argc, char * argv[]) { boost::context::execution_context bar_ctx( #if defined(BOOST_USE_SEGMENTED_STACKS) - boost::context::segmented(), + boost::context::segmented_stack(), #else - boost::context::fixedsize(), + boost::context::fixedsize_stack(), #endif [& main_ctx, count](){ bar( count); diff --git a/include/boost/context/all.hpp b/include/boost/context/all.hpp index 78cb07f..f037877 100644 --- a/include/boost/context/all.hpp +++ b/include/boost/context/all.hpp @@ -5,9 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include -#include -#include +#include +#include +#include #include #include #if __cplusplus >= 201103L diff --git a/include/boost/context/detail/config.hpp b/include/boost/context/detail/config.hpp index 621b6a2..df8efca 100644 --- a/include/boost/context/detail/config.hpp +++ b/include/boost/context/detail/config.hpp @@ -49,7 +49,7 @@ #if defined(BOOST_USE_SEGMENTED_STACKS) # if ! ( (defined(__GNUC__) && __GNUC__ > 3 && __GNUC_MINOR__ > 6) || \ (defined(__clang__) && __clang_major__ > 2 && __clang_minor__ > 3) ) -# error "compiler does not support segmented stacks" +# error "compiler does not support segmented_stack stacks" # endif # define BOOST_CONTEXT_SEGMENTS 10 #endif diff --git a/include/boost/context/execution_context.hpp b/include/boost/context/execution_context.hpp index 11c18d4..bc34b15 100644 --- a/include/boost/context/execution_context.hpp +++ b/include/boost/context/execution_context.hpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -142,7 +142,7 @@ private: boost::intrusive_ptr< fcontext > ptr_; #if defined(BOOST_USE_SEGMENTED_STACKS) - bool use_segmented_ = false; + bool use_segmented_stack_ = false; #endif template< typename StackAlloc, typename Fn > @@ -214,19 +214,19 @@ public: #if defined(BOOST_USE_SEGMENTED_STACKS) template< typename Fn, typename ... Args > - explicit execution_context( segmented salloc, Fn && fn, Args && ... args) : + explicit execution_context( segmented_stack salloc, Fn && fn, Args && ... args) : ptr_( create_worker_fcontext( salloc, detail::fn_rref< Fn >( std::forward< Fn >( fn) ), detail::arg_rref< Args >( std::forward< Args >( args) ) ... ) ), - use_segmented_( true) { + use_segmented_stack_( true) { } template< typename Fn, typename ... Args > - explicit execution_context( preallocated palloc, segmented salloc, Fn && fn, Args && ... args) : + explicit execution_context( preallocated palloc, segmented_stack salloc, Fn && fn, Args && ... args) : ptr_( create_worker_fcontext( palloc, salloc, detail::fn_rref< Fn >( std::forward< Fn >( fn) ), detail::arg_rref< Args >( std::forward< Args >( args) ) ... ) ), - use_segmented_( true) { + use_segmented_stack_( true) { } #endif @@ -249,7 +249,7 @@ public: fcontext * tmp( current_ctx_.get() ); current_ctx_ = ptr_; #if defined(BOOST_USE_SEGMENTED_STACKS) - if ( use_segmented_) { + if ( use_segmented_stack_) { __splitstack_getcontext( tmp->sctx.segments_ctx); __splitstack_setcontext( ptr_->sctx.segments_ctx); diff --git a/include/boost/context/fixedsize.hpp b/include/boost/context/fixedsize_stack.hpp similarity index 90% rename from include/boost/context/fixedsize.hpp rename to include/boost/context/fixedsize_stack.hpp index b4a5cb9..6d1858e 100644 --- a/include/boost/context/fixedsize.hpp +++ b/include/boost/context/fixedsize_stack.hpp @@ -26,14 +26,14 @@ namespace boost { namespace context { template< typename traitsT > -class basic_fixedsize { +class basic_fixedsize_stack { private: std::size_t size_; public: typedef traitsT traits_type; - basic_fixedsize( std::size_t size = traits_type::default_size() ) : + basic_fixedsize_stack( std::size_t size = traits_type::default_size() ) : size_( size) { BOOST_ASSERT( traits_type::minimum_size() <= size_); BOOST_ASSERT( traits_type::is_unbounded() || ( traits_type::maximum_size() >= size_) ); @@ -59,7 +59,7 @@ public: } }; -typedef basic_fixedsize< stack_traits > fixedsize; +typedef basic_fixedsize_stack< stack_traits > fixedsize_stack; }} diff --git a/include/boost/context/posix/protected_fixedsize.hpp b/include/boost/context/posix/protected_fixedsize_stack.hpp similarity index 93% rename from include/boost/context/posix/protected_fixedsize.hpp rename to include/boost/context/posix/protected_fixedsize_stack.hpp index fe827d9..a050bdf 100644 --- a/include/boost/context/posix/protected_fixedsize.hpp +++ b/include/boost/context/posix/protected_fixedsize_stack.hpp @@ -33,14 +33,14 @@ namespace boost { namespace context { template< typename traitsT > -class basic_protected_fixedsize { +class basic_protected_fixedsize_stack { private: std::size_t size_; public: typedef traitsT traits_type; - basic_protected_fixedsize( std::size_t size = traits_type::default_size() ) : + basic_protected_fixedsize_stack( std::size_t size = traits_type::default_size() ) : size_( size) { BOOST_ASSERT( traits_type::minimum_size() <= size_); BOOST_ASSERT( traits_type::is_unbounded() || ( traits_type::maximum_size() >= size_) ); @@ -90,7 +90,7 @@ public: } }; -typedef basic_protected_fixedsize< stack_traits > protected_fixedsize; +typedef basic_protected_fixedsize_stack< stack_traits > protected_fixedsize_stack; }} diff --git a/include/boost/context/posix/segmented.hpp b/include/boost/context/posix/segmented_stack.hpp similarity index 92% rename from include/boost/context/posix/segmented.hpp rename to include/boost/context/posix/segmented_stack.hpp index 12bf543..f4a32d7 100644 --- a/include/boost/context/posix/segmented.hpp +++ b/include/boost/context/posix/segmented_stack.hpp @@ -38,14 +38,14 @@ namespace boost { namespace context { template< typename traitsT > -class basic_segmented { +class basic_segmented_stack { private: std::size_t size_; public: typedef traitsT traits_type; - basic_segmented( std::size_t size = traits_type::default_size() ) : + basic_segmented_stack( std::size_t size = traits_type::default_size() ) : size_( size) { BOOST_ASSERT( traits_type::minimum_size() <= size_); BOOST_ASSERT( traits_type::is_unbounded() || ( traits_type::maximum_size() >= size_) ); @@ -70,7 +70,7 @@ public: } }; -typedef basic_segmented< stack_traits > segmented; +typedef basic_segmented_stack< stack_traits > segmented_stack; }} diff --git a/include/boost/context/protected_fixedsize.hpp b/include/boost/context/protected_fixedsize_stack.hpp similarity index 69% rename from include/boost/context/protected_fixedsize.hpp rename to include/boost/context/protected_fixedsize_stack.hpp index ce7a8be..a05aa73 100644 --- a/include/boost/context/protected_fixedsize.hpp +++ b/include/boost/context/protected_fixedsize_stack.hpp @@ -7,7 +7,7 @@ #include #if defined(BOOST_WINDOWS) -# include +# include #else -# include +# include #endif diff --git a/include/boost/context/segmented.hpp b/include/boost/context/segmented_stack.hpp similarity index 86% rename from include/boost/context/segmented.hpp rename to include/boost/context/segmented_stack.hpp index 3acf820..88e3e6a 100644 --- a/include/boost/context/segmented.hpp +++ b/include/boost/context/segmented_stack.hpp @@ -8,6 +8,6 @@ #if defined(BOOST_USE_SEGMENTED_STACKS) # if ! defined(BOOST_WINDOWS) -# include +# include # endif #endif diff --git a/include/boost/context/windows/protected_fixedsize.hpp b/include/boost/context/windows/protected_fixedsize_stack.hpp similarity index 92% rename from include/boost/context/windows/protected_fixedsize.hpp rename to include/boost/context/windows/protected_fixedsize_stack.hpp index 26ca326..478c8c4 100644 --- a/include/boost/context/windows/protected_fixedsize.hpp +++ b/include/boost/context/windows/protected_fixedsize_stack.hpp @@ -29,14 +29,14 @@ namespace boost { namespace context { template< typename traitsT > -class basic_protected_fixedsize { +class basic_protected_fixedsize_stack { private: std::size_t size_; public: typedef traitsT traits_type; - basic_protected_fixedsize( std::size_t size = traits_type::default_size() ) : + basic_protected_fixedsize_stack( std::size_t size = traits_type::default_size() ) : size_( size) { BOOST_ASSERT( traits_type::minimum_size() <= size_); BOOST_ASSERT( traits_type::is_unbounded() || ( traits_type::maximum_size() >= size_) ); @@ -82,7 +82,7 @@ public: } }; -typedef basic_protected_fixedsize< stack_traits > protected_fixedsize; +typedef basic_protected_fixedsize_stack< stack_traits > protected_fixedsize_stack; }} diff --git a/performance/clock.hpp b/performance/clock.hpp index 6103951..d8222bb 100644 --- a/performance/clock.hpp +++ b/performance/clock.hpp @@ -29,6 +29,7 @@ struct clock_overhead } }; +inline duration_type overhead_clock() { std::size_t iterations( 10); diff --git a/performance/fcontext/Jamfile.v2 b/performance/fcontext/Jamfile.v2 index 806c4b9..13b1ef3 100644 --- a/performance/fcontext/Jamfile.v2 +++ b/performance/fcontext/Jamfile.v2 @@ -18,6 +18,10 @@ project boost/context/performance/fcontext /boost/chrono//boost_chrono /boost/context//boost_context /boost/program_options//boost_program_options + gcc,on:-fsplit-stack + gcc,on:-DBOOST_USE_SEGMENTED_STACKS + clang,on:-fsplit-stack + clang,on:-DBOOST_USE_SEGMENTED_STACKS static speed multi diff --git a/performance/fcontext/performance_fcontext.cpp b/performance/fcontext/performance_fcontext.cpp index 5853e7b..f9f227c 100644 --- a/performance/fcontext/performance_fcontext.cpp +++ b/performance/fcontext/performance_fcontext.cpp @@ -66,7 +66,7 @@ duration_type measure_time_ec() { boost::context::execution_context ctx( boost::context::execution_context::current() ); mctx = & ctx; // cache warum-up - boost::context::fixedsize alloc; + boost::context::fixedsize_stack alloc; boost::context::execution_context ectx( alloc, bar); ectx.jump_to(); @@ -105,7 +105,7 @@ cycle_type measure_cycles_ec() { boost::context::execution_context ctx( boost::context::execution_context::current() ); mctx = & ctx; // cache warum-up - boost::context::fixedsize alloc; + boost::context::fixedsize_stack alloc; boost::context::execution_context ectx( alloc, bar); ectx.jump_to(); diff --git a/src/posix/stack_traits.cpp b/src/posix/stack_traits.cpp index 7cc0d51..64a4fb7 100644 --- a/src/posix/stack_traits.cpp +++ b/src/posix/stack_traits.cpp @@ -20,11 +20,7 @@ extern "C" { #include #include -#if __cplusplus < 201103L # include -#else -# include -#endif #if !defined (SIGSTKSZ) # define SIGSTKSZ (8 * 1024) @@ -38,7 +34,6 @@ extern "C" { namespace boost { namespace context { -#if __cplusplus < 201103L void pagesize_( std::size_t * size) { // conform to POSIX.1-2001 @@ -71,23 +66,6 @@ rlimit stacksize_limit() boost::call_once( flag, stacksize_limit_, & limit); return limit; } -#else -std::size_t pagesize() -{ - static std::size_t size = 0; - static std::once_flag flag; - std::call_once( flag, [](){ size = ::sysconf( _SC_PAGESIZE); }); - return size; -} - -rlimit stacksize_limit() -{ - static rlimit limit; - static std::once_flag flag; - std::call_once( flag, [](){ ::getrlimit( RLIMIT_STACK, & limit); }); - return limit; -} -#endif bool stack_traits::is_unbounded() BOOST_NOEXCEPT diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f9498a4..12af800 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -17,6 +17,10 @@ project boost/context/test : requirements ../../test/build//boost_unit_test_framework /boost/context//boost_context + gcc,on:-fsplit-stack + gcc,on:-DBOOST_USE_SEGMENTED_STACKS + clang,on:-fsplit-stack + clang,on:-DBOOST_USE_SEGMENTED_STACKS static multi ; diff --git a/test/test_context.cpp b/test/test_context.cpp index cd6e974..ce735cd 100644 --- a/test/test_context.cpp +++ b/test/test_context.cpp @@ -238,7 +238,7 @@ void test_ectx() { boost::context::execution_context ctx( boost::context::execution_context::current() ); mctx = & ctx; value1 = 0; - ctx::fixedsize alloc; + ctx::fixedsize_stack alloc; ctx::execution_context ectx( alloc, f11); ectx.jump_to(); BOOST_CHECK_EQUAL( 3, value1); @@ -248,7 +248,7 @@ void test_variadric() { boost::context::execution_context ctx( boost::context::execution_context::current() ); mctx = & ctx; value1 = 0; - ctx::fixedsize alloc; + ctx::fixedsize_stack alloc; ctx::execution_context ectx( alloc, f12, 5); ectx.jump_to(); BOOST_CHECK_EQUAL( 5, value1); @@ -258,7 +258,7 @@ void test_prealloc() { boost::context::execution_context ctx( boost::context::execution_context::current() ); mctx = & ctx; value1 = 0; - ctx::fixedsize alloc; + ctx::fixedsize_stack alloc; ctx::stack_context sctx( alloc.allocate() ); void * sp = static_cast< char * >( sctx.sp) - 10; std::size_t size = sctx.size - 10;