2
0
mirror of https://github.com/boostorg/context.git synced 2026-01-19 04:02:17 +00:00

me stack-allocators/some fixes

This commit is contained in:
Oliver Kowalke
2015-01-23 22:02:20 +01:00
parent 9ec7f56a5a
commit fa078765cb
20 changed files with 77 additions and 108 deletions

View File

@@ -19,17 +19,13 @@ feature.compose <segmented-stacks>on : <define>BOOST_USE_SEGMENTED_STACKS ;
project boost/context
: requirements
<library>/boost/system//boost_system
<library>/boost/thread//boost_thread
<os>SOLARIS:<define>_XOPEN_SOURCE=600
<toolset>gcc-4.7,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc-4.7,<segmented-stacks>on:<linkflags>"-static-libgcc"
<toolset>gcc-4.8,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc-4.8,<segmented-stacks>on:<linkflags>"-static-libgcc"
<toolset>gcc-4.9,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc-4.9,<segmented-stacks>on:<linkflags>"-static-libgcc"
<toolset>clang-3.4,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>clang-3.4,<segmented-stacks>on:<linkflags>"-static-libgcc"
<toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>gcc,<segmented-stacks>on:<linkflags>"-static-libgcc"
<toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>clang,<segmented-stacks>on:<linkflags>"-static-libgcc"
<link>shared:<define>BOOST_CONTEXT_DYN_LINK=1
<define>BOOST_CONTEXT_SOURCE
<threading>multi

View File

@@ -15,18 +15,13 @@ import os ;
import toolset ;
import architecture ;
project boost/econtext/example
project boost/context/example/execution_context
: requirements
<library>/boost/context//boost_context
<library>/boost/thread//boost_thread
<toolset>gcc-4.7,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc-4.7,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>gcc-4.8,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc-4.8,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>gcc-4.9,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc-4.9,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>clang-3.4,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>clang-3.4,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<link>static
<threading>multi
;

View File

@@ -5,14 +5,9 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <boost/assert.hpp>
#include <boost/context/execution_context.hpp>
#include <boost/context/fixedsize.hpp>
#include <boost/context/protected_fixedsize.hpp>
#include <boost/context/all.hpp>
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_;

View File

@@ -4,14 +4,12 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <sstream>
#include <thread>
#include <boost/context/execution_context.hpp>
#include <boost/context/fixedsize.hpp>
#include <boost/context/all.hpp>
/*
* 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;
}

View File

@@ -4,14 +4,12 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdlib>
#include <iostream>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/context/execution_context.hpp>
#include <boost/context/fixedsize.hpp>
#include <boost/context/segmented.hpp>
#include <boost/context/all.hpp>
#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);

View File

@@ -5,9 +5,9 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/context/fcontext.hpp>
#include <boost/context/fixedsize.hpp>
#include <boost/context/protected_fixedsize.hpp>
#include <boost/context/segmented.hpp>
#include <boost/context/fixedsize_stack.hpp>
#include <boost/context/protected_fixedsize_stack.hpp>
#include <boost/context/segmented_stack.hpp>
#include <boost/context/stack_context.hpp>
#include <boost/context/stack_traits.hpp>
#if __cplusplus >= 201103L

View File

@@ -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

View File

@@ -25,7 +25,7 @@
#include <boost/context/detail/config.hpp>
#include <boost/context/detail/rref.hpp>
#include <boost/context/stack_context.hpp>
#include <boost/context/segmented.hpp>
#include <boost/context/segmented_stack.hpp>
#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);

View File

@@ -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;
}}

View File

@@ -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;
}}

View File

@@ -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;
}}

View File

@@ -7,7 +7,7 @@
#include <boost/config.hpp>
#if defined(BOOST_WINDOWS)
# include <boost/context/windows/protected_fixedsize.hpp>
# include <boost/context/windows/protected_fixedsize_stack.hpp>
#else
# include <boost/context/posix/protected_fixedsize.hpp>
# include <boost/context/posix/protected_fixedsize_stack.hpp>
#endif

View File

@@ -8,6 +8,6 @@
#if defined(BOOST_USE_SEGMENTED_STACKS)
# if ! defined(BOOST_WINDOWS)
# include <boost/context/posix/segmented.hpp>
# include <boost/context/posix/segmented_stack.hpp>
# endif
#endif

View File

@@ -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;
}}

View File

@@ -29,6 +29,7 @@ struct clock_overhead
}
};
inline
duration_type overhead_clock()
{
std::size_t iterations( 10);

View File

@@ -18,6 +18,10 @@ project boost/context/performance/fcontext
<library>/boost/chrono//boost_chrono
<library>/boost/context//boost_context
<library>/boost/program_options//boost_program_options
<toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<link>static
<optimization>speed
<threading>multi

View File

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

View File

@@ -20,11 +20,7 @@ extern "C" {
#include <boost/assert.hpp>
#include <boost/config.hpp>
#if __cplusplus < 201103L
# include <boost/thread.hpp>
#else
# include <mutex>
#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

View File

@@ -17,6 +17,10 @@ project boost/context/test
: requirements
<library>../../test/build//boost_unit_test_framework
<library>/boost/context//boost_context
<toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<link>static
<threading>multi
;

View File

@@ -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;