diff --git a/doc/context.xml b/doc/context.xml index 61c80a9..ea6ed23 100644 --- a/doc/context.xml +++ b/doc/context.xml @@ -508,21 +508,21 @@ [&main_ctx,&c](char ch){ c=ch; // resume main execution context - main_ctx.jump_to(); + main_ctx.resume(); }); // start recursive parsing p.run(); done=true; // return to main execution context - main_ctx.jump_to(); + main_ctx.resume(); }); // user-code pulls parsed data from parser // inverted control flow - parser_ctx.jump_to(); + parser_ctx.resume(); do { printf("Parsed: %c\n",c); - parser_ctx.jump_to(); + parser_ctx.resume(); } while( ! done); } @@ -612,7 +612,7 @@ template< typename StackAlloc, typename Fn, typename ... Args > execution_context( preallocated palloc, StackAlloc salloc, Fn && fn, Args && ... args); - void jump_to() noexcept; + void resume() noexcept; explicit operator bool() const noexcept; @@ -756,9 +756,9 @@ - void jump_tovoid resume() diff --git a/doc/execution_context.qbk b/doc/execution_context.qbk index a9a303e..82fba00 100644 --- a/doc/execution_context.qbk +++ b/doc/execution_context.qbk @@ -43,21 +43,21 @@ __econtext__ permits access to the current, active context via [&main_ctx,&c](char ch){ c=ch; // resume main execution context - main_ctx.jump_to(); + main_ctx.resume(); }); // start recursive parsing p.run(); done=true; // return to main execution context - main_ctx.jump_to(); + main_ctx.resume(); }); // user-code pulls parsed data from parser // inverted control flow - parser_ctx.jump_to(); + parser_ctx.resume(); do { printf("Parsed: %c\n",c); - parser_ctx.jump_to(); + parser_ctx.resume(); } while( ! done); } @@ -89,6 +89,8 @@ pattern). The user is responsible for this task. Allocating control structures on top of the stack requires to allocated the __stack_context__ and create the control structure with placement new before __econtext__ is created. +[note The user is responsible for destructing the control structure at the top +of the stack.] // stack-alloctor used for (de-)allocating stack fixedsize_stack salloc( 4048); @@ -100,6 +102,9 @@ __econtext__ is created. // placement new creates control structure on reserved space my_control_structure * cs = new ( sp) my_control_structure( sp, size, sctx, salloc); ... + // destructing the control structure + cs->~my_control_structure(); + ... struct my_control_structure { // execution context execution_context ectx; @@ -131,7 +136,7 @@ __econtext__ is created. template< typename StackAlloc, typename Fn, typename ... Args > execution_context( preallocated palloc, StackAlloc salloc, Fn && fn, Args && ... args); - void jump_to() noexcept; + void resume() noexcept; explicit operator bool() const noexcept; @@ -169,12 +174,14 @@ execution context.]] `fn`. Used to store control structures on top of the stack.]] ] -[heading `void jump_to()`] +[heading `void resume()`] [variablelist [[Effects:] [Stores internally the current context data (stack pointer, instruction pointer, and CPU registers) to the current active context and restores the context data from `*this`, which implies jumping to `*this`'s execution context.]] +[[Note:] [The behaviour is undefined if `resume()` is called while `execution_context::current()` +returns `*this` (e.g. resuming an alredy running cotnext).]] [[Throws:] [Nothing.]] ] diff --git a/doc/html/context/econtext.html b/doc/html/context/econtext.html index 3a4ea19..5647f55 100644 --- a/doc/html/context/econtext.html +++ b/doc/html/context/econtext.html @@ -70,21 +70,21 @@ [&main_ctx,&c](char ch){ c=ch; // resume main execution context - main_ctx.jump_to(); + main_ctx.resume(); }); // start recursive parsing p.run(); done=true; // return to main execution context - main_ctx.jump_to(); + main_ctx.resume(); }); // user-code pulls parsed data from parser // inverted control flow - parser_ctx.jump_to(); + parser_ctx.resume(); do { printf("Parsed: %c\n",c); - parser_ctx.jump_to(); + parser_ctx.resume(); } while( ! done); } @@ -177,7 +177,7 @@ template< typename StackAlloc, typename Fn, typename ... Args > execution_context( preallocated palloc, StackAlloc salloc, Fn && fn, Args && ... args); - void jump_to() noexcept; + void resume() noexcept; explicit operator bool() const noexcept; @@ -276,7 +276,7 @@

- void jump_to() + void resume()

diff --git a/example/execution_context/jump.cpp b/example/execution_context/jump.cpp index 01baa87..1a48ca4 100644 --- a/example/execution_context/jump.cpp +++ b/example/execution_context/jump.cpp @@ -16,16 +16,16 @@ boost::context::execution_context * ctx = nullptr; void f1( int i) { std::cout << "f1: entered" << std::endl; std::cout << "i == " << i << std::endl; - ctx2->jump_to(); + ctx2->resume(); std::cout << "f1: re-entered" << std::endl; - ctx2->jump_to(); + ctx2->resume(); } void f2() { std::cout << "f2: entered" << std::endl; - ctx1->jump_to(); + ctx1->resume(); std::cout << "f2: re-entered" << std::endl; - ctx->jump_to(); + ctx->resume(); } int main() { @@ -36,7 +36,7 @@ int main() { boost::context::execution_context ctx_( boost::context::execution_context::current() ); ctx = & ctx_; - ctx1->jump_to(); + ctx1->resume(); std::cout << "main: done" << std::endl; diff --git a/example/execution_context/parser.cpp b/example/execution_context/parser.cpp index 2c00311..da16fee 100644 --- a/example/execution_context/parser.cpp +++ b/example/execution_context/parser.cpp @@ -103,20 +103,20 @@ int main() { [&main_ctx,&c](char ch){ c=ch; // resume main execution context - main_ctx.jump_to(); + main_ctx.resume(); }); // start recursive parsing p.run(); done=true; - main_ctx.jump_to(); + main_ctx.resume(); }); // user-code pulls parsed data from parser // invert control flow - parser_ctx.jump_to(); + parser_ctx.resume(); do { printf("Parsed: %c\n",c); - parser_ctx.jump_to(); + parser_ctx.resume(); } while( ! done); std::cout << "main: done" << std::endl; diff --git a/example/execution_context/segmented.cpp b/example/execution_context/segmented.cpp index f076f48..6f5e457 100644 --- a/example/execution_context/segmented.cpp +++ b/example/execution_context/segmented.cpp @@ -57,10 +57,10 @@ int main() { #endif [& main_ctx, count](){ bar( count); - main_ctx.jump_to(); + main_ctx.resume(); }); - bar_ctx.jump_to(); + bar_ctx.resume(); std::cout << "main: done" << std::endl; diff --git a/include/boost/context/execution_context.hpp b/include/boost/context/execution_context.hpp index 751c78f..4d809b0 100644 --- a/include/boost/context/execution_context.hpp +++ b/include/boost/context/execution_context.hpp @@ -275,8 +275,7 @@ public: std::index_sequence_for< Args ... >() ) ) { } - void jump_to( bool preserve_fpu = false) noexcept { - BOOST_ASSERT( * this); + void resume( bool preserve_fpu = false) noexcept { fcontext * old_ctx( current_ctx_.get() ); fcontext * new_ctx( ptr_.get() ); current_ctx_ = ptr_; diff --git a/performance/fcontext/performance_fcontext.cpp b/performance/fcontext/performance_fcontext.cpp index f9f227c..3e370c1 100644 --- a/performance/fcontext/performance_fcontext.cpp +++ b/performance/fcontext/performance_fcontext.cpp @@ -40,7 +40,7 @@ static void foo( intptr_t) { #if __cplusplus >= 201103L static void bar() { while ( true) { - mctx->jump_to(); + mctx->resume(); } } #endif @@ -68,11 +68,11 @@ duration_type measure_time_ec() { // cache warum-up boost::context::fixedsize_stack alloc; boost::context::execution_context ectx( alloc, bar); - ectx.jump_to(); + ectx.resume(); time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { - ectx.jump_to(); + ectx.resume(); } duration_type total = clock_type::now() - start; total -= overhead_clock(); // overhead of measurement @@ -107,11 +107,11 @@ cycle_type measure_cycles_ec() { // cache warum-up boost::context::fixedsize_stack alloc; boost::context::execution_context ectx( alloc, bar); - ectx.jump_to(); + ectx.resume(); cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { - ectx.jump_to(); + ectx.resume(); } cycle_type total = cycles() - start; total -= overhead_cycle(); // overhead of measurement diff --git a/test/test_context.cpp b/test/test_context.cpp index 7098729..85797b2 100644 --- a/test/test_context.cpp +++ b/test/test_context.cpp @@ -227,12 +227,12 @@ ctx::execution_context * mctx = nullptr; void f11() { value1 = 3; - mctx->jump_to(); + mctx->resume(); } void f12( int i) { value1 = i; - mctx->jump_to(); + mctx->resume(); } void test_ectx() { @@ -241,7 +241,7 @@ void test_ectx() { value1 = 0; ctx::fixedsize_stack alloc; ctx::execution_context ectx( alloc, f11); - ectx.jump_to(); + ectx.resume(); BOOST_CHECK_EQUAL( 3, value1); } @@ -251,7 +251,7 @@ void test_variadric() { value1 = 0; ctx::fixedsize_stack alloc; ctx::execution_context ectx( alloc, f12, 5); - ectx.jump_to(); + ectx.resume(); BOOST_CHECK_EQUAL( 5, value1); } @@ -264,7 +264,7 @@ void test_prealloc() { void * sp = static_cast< char * >( sctx.sp) - 10; std::size_t size = sctx.size - 10; ctx::execution_context ectx( ctx::preallocated( sp, size, sctx), alloc, f12, 7); - ectx.jump_to(); + ectx.resume(); BOOST_CHECK_EQUAL( 7, value1); } #endif