diff --git a/example/echosse.cpp b/example/echosse.cpp index 7f4abd0..da66738 100644 --- a/example/echosse.cpp +++ b/example/echosse.cpp @@ -34,12 +34,12 @@ int main( int argc, char * argv[]) { std::cout << i; echoSSE( i); std::cout << " "; - f.resume(); + f = f.resume(); } return std::move( f); }}; for (; i < 11; ++i) { - f.resume(); + f = f.resume(); } std::cout << "\nmain: done" << std::endl; return EXIT_SUCCESS; diff --git a/example/endless_loop.cpp b/example/endless_loop.cpp index 79eedd3..98f61dc 100644 --- a/example/endless_loop.cpp +++ b/example/endless_loop.cpp @@ -14,7 +14,7 @@ namespace ctx = boost::context; ctx::fiber bar( ctx::fiber && f) { do { std::cout << "bar\n"; - f.resume(); + f = f.resume(); } while ( f); return std::move( f); } @@ -23,7 +23,7 @@ int main() { ctx::fiber f{ bar }; do { std::cout << "foo\n"; - f.resume(); + f = f.resume(); } while ( f); std::cout << "main: done" << std::endl; return EXIT_SUCCESS; diff --git a/example/fibonacci.cpp b/example/fibonacci.cpp index 8f2589c..8780d97 100644 --- a/example/fibonacci.cpp +++ b/example/fibonacci.cpp @@ -19,7 +19,7 @@ int main() { a=0; int b=1; for(;;){ - f.resume(); + f = f.resume(); int next=a+b; a=b; b=next; @@ -27,7 +27,7 @@ int main() { return std::move( f); }}; for ( int j = 0; j < 10; ++j) { - f.resume(); + f = f.resume(); std::cout << a << " "; } std::cout << std::endl; diff --git a/example/jump.cpp b/example/jump.cpp index 050ae90..11fb2d3 100644 --- a/example/jump.cpp +++ b/example/jump.cpp @@ -17,14 +17,14 @@ int main() { [&data](ctx::fiber && f){ std::cout << "entered first time: " << data << std::endl; data += 2; - f.resume(); + f = f.resume(); std::cout << "entered second time: " << data << std::endl; return std::move( f); }}; - f.resume(); + f = f.resume(); std::cout << "returned first time: " << data << std::endl; data += 2; - f.resume(); + f = f.resume(); if ( f) { std::cout << "returned second time: " << data << std::endl; } else { diff --git a/example/jump_mov.cpp b/example/jump_mov.cpp index 3b8c416..1ec9ae4 100644 --- a/example/jump_mov.cpp +++ b/example/jump_mov.cpp @@ -44,15 +44,15 @@ int main() { [&data](ctx::fiber && f){ std::cout << "entered first time: " << data.value << std::endl; data = std::move( moveable{ 3 }); - f.resume(); + f = f.resume(); std::cout << "entered second time: " << data.value << std::endl; data = std::move( moveable{}); return std::move( f); }}; - f.resume(); + f = f.resume(); std::cout << "returned first time: " << data.value << std::endl; data.value = 5; - f.resume(); + f = f.resume(); std::cout << "returned second time: " << data.value << std::endl; std::cout << "main: done" << std::endl; return EXIT_SUCCESS; diff --git a/example/jump_void.cpp b/example/jump_void.cpp index ddc8309..1d9aa29 100644 --- a/example/jump_void.cpp +++ b/example/jump_void.cpp @@ -13,16 +13,16 @@ namespace ctx = boost::context; ctx::fiber f1( ctx::fiber && f) { std::cout << "f1: entered first time" << std::endl; - f.resume(); + f = f.resume(); std::cout << "f1: entered second time" << std::endl; return std::move( f); } int main() { ctx::fiber f{ f1 }; - f.resume(); + f = f.resume(); std::cout << "f1: returned first time" << std::endl; - f.resume(); + f = f.resume(); std::cout << "f1: returned second time" << std::endl; std::cout << "main: done" << std::endl; return EXIT_SUCCESS; diff --git a/example/ontop.cpp b/example/ontop.cpp index 7a868e7..da143b9 100644 --- a/example/ontop.cpp +++ b/example/ontop.cpp @@ -17,20 +17,20 @@ int main() { ctx::fiber f{ [&data](ctx::fiber && f) { std::cout << "f1: entered first time: " << data << std::endl; data += 1; - f.resume(); + f = f.resume(); std::cout << "f1: entered second time: " << data << std::endl; data += 1; - f.resume(); + f = f.resume(); std::cout << "f1: entered third time: " << data << std::endl; return std::move( f); }}; - f.resume(); + f = f.resume(); std::cout << "f1: returned first time: " << data << std::endl; data += 1; - f.resume(); + f = f.resume(); std::cout << "f1: returned second time: " << data << std::endl; data += 1; - f.resume_with([&data](ctx::fiber && f){ + f = f.resume_with([&data](ctx::fiber && f){ std::cout << "f2: entered: " << data << std::endl; data = -1; return std::move( f); diff --git a/example/ontop_void.cpp b/example/ontop_void.cpp index 76808bf..df801d0 100644 --- a/example/ontop_void.cpp +++ b/example/ontop_void.cpp @@ -14,9 +14,9 @@ namespace ctx = boost::context; ctx::fiber f1( ctx::fiber && f) { std::cout << "f1: entered first time" << std::endl; - f.resume(); + f = f.resume(); std::cout << "f1: entered second time" << std::endl; - f.resume(); + f = f.resume(); std::cout << "f1: entered third time" << std::endl; return std::move( f); } @@ -28,11 +28,11 @@ ctx::fiber f2( ctx::fiber && f) { int main() { ctx::fiber f{ f1 }; - f.resume(); + f = f.resume(); std::cout << "f1: returned first time" << std::endl; - f.resume(); + f = f.resume(); std::cout << "f1: returned second time" << std::endl; - f.resume_with( f2); + f = f.resume_with( f2); std::cout << "f1: returned third time" << std::endl; std::cout << "main: done" << std::endl; diff --git a/example/parser.cpp b/example/parser.cpp index efc5c31..81d49c8 100644 --- a/example/parser.cpp +++ b/example/parser.cpp @@ -105,7 +105,7 @@ int main() { [&sink,&c](char c_){ // resume main execution context c = c_; - sink.resume(); + sink = sink.resume(); }); // start recursive parsing p.run(); @@ -114,10 +114,10 @@ int main() { // resume main execution context return std::move(sink); }}; - source.resume(); + source = source.resume(); while(!done){ printf("Parsed: %c\n",c); - source.resume(); + source = source.resume(); } std::cout << "main: done" << std::endl; return EXIT_SUCCESS; diff --git a/example/throw.cpp b/example/throw.cpp index 204ee92..b22b604 100644 --- a/example/throw.cpp +++ b/example/throw.cpp @@ -27,7 +27,7 @@ int main() { for (;;) { try { std::cout << "entered" << std::endl; - f.resume(); + f = f.resume(); } catch ( my_exception & ex) { std::cerr << "my_exception: " << ex.what() << std::endl; return std::move( ex.f); @@ -35,8 +35,8 @@ int main() { } return std::move( f); }}; - f.resume(); - f.resume_with([](ctx::fiber && f){ + f = f.resume(); + f = f.resume_with([](ctx::fiber && f){ throw my_exception(std::move( f), "abc"); return std::move( f); }); diff --git a/include/boost/context/fiber_fcontext.hpp b/include/boost/context/fiber_fcontext.hpp index 9b138f0..77274f0 100644 --- a/include/boost/context/fiber_fcontext.hpp +++ b/include/boost/context/fiber_fcontext.hpp @@ -275,29 +275,29 @@ public: fiber( fiber const& other) noexcept = delete; fiber & operator=( fiber const& other) noexcept = delete; - void resume() { + fiber resume() { BOOST_ASSERT( nullptr != fctx_); - fctx_ = detail::jump_fcontext( + return fiber{ detail::jump_fcontext( #if defined(BOOST_NO_CXX14_STD_EXCHANGE) detail::exchange( fctx_, nullptr), #else std::exchange( fctx_, nullptr), #endif - nullptr).fctx; + nullptr).fctx }; } template< typename Fn > - void resume_with( Fn && fn) { + fiber resume_with( Fn && fn) { BOOST_ASSERT( nullptr != fctx_); auto p = std::make_tuple( std::forward< Fn >( fn) ); - fctx_ = detail::ontop_fcontext( + return fiber{ detail::ontop_fcontext( #if defined(BOOST_NO_CXX14_STD_EXCHANGE) detail::exchange( fctx_, nullptr), #else std::exchange( fctx_, nullptr), #endif & p, - detail::context_ontop< fiber, Fn >).fctx; + detail::context_ontop< fiber, Fn >).fctx }; } explicit operator bool() const noexcept { diff --git a/include/boost/context/fiber_ucontext.hpp b/include/boost/context/fiber_ucontext.hpp index 3cedff0..c9c52e2 100644 --- a/include/boost/context/fiber_ucontext.hpp +++ b/include/boost/context/fiber_ucontext.hpp @@ -432,7 +432,7 @@ public: return * this; } - void resume() { + fiber resume() { BOOST_ASSERT( nullptr != ptr_); #if defined(BOOST_NO_CXX14_STD_EXCHANGE) detail::activation_record * ptr = detail::exchange( ptr_, nullptr)->resume(); @@ -445,11 +445,11 @@ public: ptr = detail::activation_record::current()->ontop( ptr); detail::activation_record::current()->ontop = nullptr; } - ptr_ = ptr; + return fiber{ ptr }; } template< typename Fn > - void resume_with( Fn && fn) { + fiber resume_with( Fn && fn) { BOOST_ASSERT( nullptr != ptr_); #if defined(BOOST_NO_CXX14_STD_EXCHANGE) detail::activation_record * ptr = @@ -464,7 +464,7 @@ public: ptr = detail::activation_record::current()->ontop( ptr); detail::activation_record::current()->ontop = nullptr; } - ptr_ = ptr; + return fiber{ ptr }; } explicit operator bool() const noexcept { diff --git a/include/boost/context/fiber_winfiber.hpp b/include/boost/context/fiber_winfiber.hpp index a4a846e..820bdb0 100644 --- a/include/boost/context/fiber_winfiber.hpp +++ b/include/boost/context/fiber_winfiber.hpp @@ -353,7 +353,7 @@ public: return * this; } - void resume() { + fiber resume() { BOOST_ASSERT( nullptr != ptr_); #if defined(BOOST_NO_CXX14_STD_EXCHANGE) detail::activation_record * ptr = detail::exchange( ptr_, nullptr)->resume(); @@ -366,11 +366,11 @@ public: ptr = detail::activation_record::current()->ontop( ptr); detail::activation_record::current()->ontop = nullptr; } - ptr_ = ptr; + return fiber{ ptr }; } template< typename Fn > - void resume_with( Fn && fn) { + fiber resume_with( Fn && fn) { BOOST_ASSERT( nullptr != ptr_); #if defined(BOOST_NO_CXX14_STD_EXCHANGE) detail::activation_record * ptr = @@ -385,7 +385,7 @@ public: ptr = detail::activation_record::current()->ontop( ptr); detail::activation_record::current()->ontop = nullptr; } - ptr_ = ptr; + return fiber{ ptr }; } explicit operator bool() const noexcept { diff --git a/test/test_fiber.cpp b/test/test_fiber.cpp index 2207469..0776b40 100644 --- a/test/test_fiber.cpp +++ b/test/test_fiber.cpp @@ -134,11 +134,11 @@ void test_move() { ctx::fiber f1{ [&i](ctx::fiber && f) { value1 = i; - f.resume(); + f = f.resume(); value1 = i; return std::move( f); }}; - f1.resume(); + f1 = f1.resume(); BOOST_CHECK_EQUAL( 1, value1); BOOST_CHECK( f1); ctx::fiber f2; @@ -147,7 +147,7 @@ void test_move() { BOOST_CHECK( ! f1); BOOST_CHECK( f2); i = 3; - f2.resume(); + f2 = f2.resume(); BOOST_CHECK_EQUAL( 3, value1); BOOST_CHECK( ! f1); BOOST_CHECK( ! f2); @@ -157,7 +157,7 @@ void test_bind() { value1 = 0; X x; ctx::fiber f{ std::bind( & X::foo, x, std::placeholders::_1, 7) }; - f.resume(); + f = f.resume(); BOOST_CHECK_EQUAL( 7, value1); } @@ -173,7 +173,7 @@ void test_exception() { } return std::move( f); }}; - f.resume(); + f = f.resume(); BOOST_CHECK_EQUAL( std::string( what), value2); BOOST_CHECK( ! f); } @@ -182,12 +182,12 @@ void test_exception() { bool catched = false; std::thread([&catched](){ ctx::fiber f{ [&catched](ctx::fiber && f){ - f.resume(); + f = f.resume(); seh( catched); return std::move( f); }}; BOOST_CHECK( f); - f.resume(); + f = f.resume(); }).join(); BOOST_CHECK( catched); } @@ -203,7 +203,7 @@ void test_fp() { value3 = d; return std::move( f); }}; - f.resume(); + f = f.resume(); BOOST_CHECK_EQUAL( 10.58, value3); BOOST_CHECK( ! f); } @@ -218,11 +218,11 @@ void test_stacked() { value1 = 3; return std::move( f); }}; - f1.resume(); + f1 = f1.resume(); value3 = 3.14; return std::move( f); }}; - f.resume(); + f = f.resume(); BOOST_CHECK_EQUAL( 3, value1); BOOST_CHECK_EQUAL( 3.14, value3); BOOST_CHECK( ! f); @@ -241,7 +241,7 @@ void test_prealloc() { value1 = i; return std::move( f); }}; - f.resume(); + f = f.resume(); BOOST_CHECK_EQUAL( 7, value1); BOOST_CHECK( ! f); } @@ -252,12 +252,12 @@ void test_ontop() { ctx::fiber f{ [&i](ctx::fiber && f) { for (;;) { i *= 10; - f.resume(); + f = f.resume(); } return std::move( f); }}; - f.resume(); - f.resume_with( + f = f.resume(); + f = f.resume_with( [&i](ctx::fiber && f){ i -= 10; return std::move( f); @@ -268,12 +268,12 @@ void test_ontop() { { ctx::fiber f1; ctx::fiber f{ [&f1](ctx::fiber && f) { - f.resume(); + f = f.resume(); BOOST_CHECK( ! f); return std::move( f1); }}; - f.resume(); - f.resume_with( + f = f.resume(); + f = f.resume_with( [&f1](ctx::fiber && f){ f1 = std::move( f); return std::move( f); @@ -288,7 +288,7 @@ void test_ontop_exception() { for (;;) { value1 = 3; try { - f.resume(); + f = f.resume(); } catch ( my_exception & ex) { value2 = ex.what(); return std::move( ex.f); @@ -296,10 +296,10 @@ void test_ontop_exception() { } return std::move( f); }}; - f.resume(); + f = f.resume(); BOOST_CHECK_EQUAL( 3, value1); const char * what = "hello world"; - f.resume_with( + f = f.resume_with( [what](ctx::fiber && f){ throw my_exception( std::move( f), what); return std::move( f); @@ -314,10 +314,10 @@ void test_termination() { ctx::fiber f{ [](ctx::fiber && f){ Y y; - f.resume(); + f = f.resume(); return std::move(f); }}; - f.resume(); + f = f.resume(); BOOST_CHECK_EQUAL( 3, value1); } BOOST_CHECK_EQUAL( 7, value1); @@ -329,7 +329,7 @@ void test_termination() { value1 = 3; return std::move( f); }}; - f.resume(); + f = f.resume(); BOOST_CHECK_EQUAL( 3, value1); BOOST_CHECK( ! f); } @@ -340,16 +340,16 @@ void test_termination() { ctx::fiber f{ [&i](ctx::fiber && f){ value1 = i; - f.resume(); + f = f.resume(); value1 = i; return std::move( f); }}; - f.resume(); + f = f.resume(); BOOST_CHECK( f); BOOST_CHECK_EQUAL( i, value1); BOOST_CHECK( f); i = 7; - f.resume(); + f = f.resume(); BOOST_CHECK( ! f); BOOST_CHECK_EQUAL( i, value1); }