From 0ecc3593008725db86a0c3bc62df7007d63260c7 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Sun, 30 Jul 2017 16:51:48 +0200 Subject: [PATCH] do not pass data via continuation::resume() --- .../detail/pull_control_block_cc.hpp | 2 - .../detail/pull_control_block_cc.ipp | 35 --------------- .../detail/push_control_block_cc.ipp | 44 ++++++------------- 3 files changed, 13 insertions(+), 68 deletions(-) diff --git a/include/boost/coroutine2/detail/pull_control_block_cc.hpp b/include/boost/coroutine2/detail/pull_control_block_cc.hpp index 44a14e2..5353fb8 100644 --- a/include/boost/coroutine2/detail/pull_control_block_cc.hpp +++ b/include/boost/coroutine2/detail/pull_control_block_cc.hpp @@ -50,7 +50,6 @@ struct pull_coroutine< T >::control_block { void set( T const&); void set( T &&); - void reset(); T & get() noexcept; @@ -89,7 +88,6 @@ struct pull_coroutine< T & >::control_block { void resume(); void set( T &); - void reset(); T & get() noexcept; diff --git a/include/boost/coroutine2/detail/pull_control_block_cc.ipp b/include/boost/coroutine2/detail/pull_control_block_cc.ipp index bde929a..4868334 100644 --- a/include/boost/coroutine2/detail/pull_control_block_cc.ipp +++ b/include/boost/coroutine2/detail/pull_control_block_cc.ipp @@ -103,9 +103,6 @@ pull_coroutine< T >::control_block::control_block( context::preallocated palloc, return other->c.resume(); }); #endif - if ( c.data_available() ) { - set( c.get_data< T >() ); - } } template< typename T > @@ -139,11 +136,6 @@ template< typename T > void pull_coroutine< T >::control_block::resume() { c = c.resume(); - if ( c.data_available() ) { - set( c.get_data< T >() ); - } else { - reset(); - } if ( except) { std::rethrow_exception( except); } @@ -171,16 +163,6 @@ pull_coroutine< T >::control_block::set( T && t) { bvalid = true; } -template< typename T > -void -pull_coroutine< T >::control_block::reset() { - // destroy data if set - if ( bvalid) { - reinterpret_cast< T * >( std::addressof( storage) )->~T(); - } - bvalid = false; -} - template< typename T > T & pull_coroutine< T >::control_block::get() noexcept { @@ -268,9 +250,6 @@ pull_coroutine< T & >::control_block::control_block( context::preallocated pallo return other->c.resume(); }); #endif - if ( c.data_available() ) { - set( c.get_data< T & >() ); - } } template< typename T > @@ -296,11 +275,6 @@ template< typename T > void pull_coroutine< T & >::control_block::resume() { c = c.resume(); - if ( c.data_available() ) { - set( c.get_data< T & >() ); - } else { - reset(); - } if ( except) { std::rethrow_exception( except); } @@ -313,15 +287,6 @@ pull_coroutine< T & >::control_block::set( T & t) { bvalid = true; } -template< typename T > -void -pull_coroutine< T & >::control_block::reset() { - if ( bvalid) { - reinterpret_cast< holder * >( std::addressof( storage) )->~holder(); - } - bvalid = false; -} - template< typename T > T & pull_coroutine< T & >::control_block::get() noexcept { diff --git a/include/boost/coroutine2/detail/push_control_block_cc.ipp b/include/boost/coroutine2/detail/push_control_block_cc.ipp index 0d2c718..98b24f2 100644 --- a/include/boost/coroutine2/detail/push_control_block_cc.ipp +++ b/include/boost/coroutine2/detail/push_control_block_cc.ipp @@ -57,12 +57,6 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, pull_coroutine< T > synthesized{ & synthesized_cb }; other = & synthesized_cb; other->c = other->c.resume(); - // set transferred value - if ( other->c.data_available() ) { - synthesized_cb.set( other->c.template get_data< T >() ); - } else { - synthesized_cb.reset(); - } if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -90,12 +84,6 @@ push_coroutine< T >::control_block::control_block( context::preallocated palloc, pull_coroutine< T > synthesized{ & synthesized_cb }; other = & synthesized_cb; other->c = other->c.resume(); - // set transferred value - if ( other->c.data_available() ) { - synthesized_cb.set( other->c.template get_data< T >() ); - } else { - synthesized_cb.reset(); - } if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -136,8 +124,10 @@ push_coroutine< T >::control_block::deallocate() noexcept { template< typename T > void push_coroutine< T >::control_block::resume( T const& data) { - // pass an pointer to other context - c = c.resume( data); + // pass data to other context + other->set( data); + // resume other context + c = c.resume(); if ( except) { std::rethrow_exception( except); } @@ -146,8 +136,10 @@ push_coroutine< T >::control_block::resume( T const& data) { template< typename T > void push_coroutine< T >::control_block::resume( T && data) { - // pass an pointer to other context - c = c.resume( std::move( data) ); + // pass data to other context + other->set( std::move( data) ); + // resume other context + c = c.resume(); if ( except) { std::rethrow_exception( except); } @@ -189,12 +181,6 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo pull_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; other->c = other->c.resume(); - // set transferred value - if ( other->c.data_available() ) { - synthesized_cb.set( other->c.template get_data< T & >() ); - } else { - synthesized_cb.reset(); - } if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -222,12 +208,6 @@ push_coroutine< T & >::control_block::control_block( context::preallocated pallo pull_coroutine< T & > synthesized{ & synthesized_cb }; other = & synthesized_cb; other->c = other->c.resume(); - // set transferred value - if ( other->c.data_available() ) { - synthesized_cb.set( other->c.template get_data< T & >() ); - } else { - synthesized_cb.reset(); - } if ( state_t::none == ( state & state_t::destroy) ) { try { auto fn = std::move( fn_); @@ -267,9 +247,11 @@ push_coroutine< T & >::control_block::deallocate() noexcept { template< typename T > void -push_coroutine< T & >::control_block::resume( T & t) { - // pass an pointer to other context - c = c.resume( std::ref( t) ); +push_coroutine< T & >::control_block::resume( T & data) { + // pass data to other context + other->set( data); + // resume other context + c = c.resume(); if ( except) { std::rethrow_exception( except); }