unwind the stack if coroutine gets terminated

- fixes #13064
- unwind the stack via exception (continuation is destroyed)
This commit is contained in:
Oliver Kowalke 2017-06-13 17:38:49 +02:00
parent b6faea151a
commit 5737fb22ae
3 changed files with 23 additions and 7 deletions

View File

@ -39,7 +39,6 @@ pull_coroutine< T >::control_block::destroy( control_block * cb) noexcept {
cb->~control_block();
// destroy coroutine's stack
cb->state |= state_t::destroy;
c.resume();
}
template< typename T >
@ -205,7 +204,6 @@ pull_coroutine< T & >::control_block::destroy( control_block * cb) noexcept {
cb->~control_block();
// destroy coroutine's stack
cb->state |= state_t::destroy;
c.resume();
}
template< typename T >
@ -347,7 +345,6 @@ pull_coroutine< void >::control_block::destroy( control_block * cb) noexcept {
cb->~control_block();
// destroy coroutine's stack
cb->state |= state_t::destroy;
c.resume();
}
template< typename StackAllocator, typename Fn >

View File

@ -38,7 +38,6 @@ push_coroutine< T >::control_block::destroy( control_block * cb) noexcept {
cb->~control_block();
// destroy coroutine's stack
cb->state |= state_t::destroy;
c.resume();
}
template< typename T >
@ -171,7 +170,6 @@ push_coroutine< T & >::control_block::destroy( control_block * cb) noexcept {
cb->~control_block();
// destroy coroutine's stack
cb->state |= state_t::destroy;
c.resume();
}
template< typename T >
@ -294,7 +292,6 @@ push_coroutine< void >::control_block::destroy( control_block * cb) noexcept {
cb->~control_block();
// destroy coroutine's stack
cb->state |= state_t::destroy;
c.resume();
}
template< typename StackAllocator, typename Fn >

View File

@ -470,7 +470,29 @@ void test_unwind()
i = 7;
});
}
BOOST_CHECK_EQUAL( ( int) 0, i);
{
BOOST_CHECK_EQUAL( ( int) 0, value1);
auto * coro = new coro::coroutine< void >::pull_type(
[](coro::coroutine< void >::push_type & coro) mutable {
X x;
coro();
});
BOOST_CHECK_EQUAL( ( int) 7, value1);
delete coro;
BOOST_CHECK_EQUAL( ( int) 0, value1);
}
{
BOOST_CHECK_EQUAL( ( int) 0, value1);
auto * coro = new coro::coroutine< void >::push_type(
[](coro::coroutine< void >::pull_type & coro) mutable {
X x;
coro();
});
( * coro)();
BOOST_CHECK_EQUAL( ( int) 7, value1);
delete coro;
BOOST_CHECK_EQUAL( ( int) 0, value1);
}
}
void test_exceptions()