apply std::allocator_arg as required by boost.context

This commit is contained in:
Oliver Kowalke 2015-09-26 20:23:04 +02:00
parent b5e475ff36
commit 4197d019f9
2 changed files with 134 additions and 132 deletions

View File

@ -8,6 +8,7 @@
#define BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_IPP #define BOOST_COROUTINES2_DETAIL_PULL_CONTROL_BLOCK_IPP
#include <exception> #include <exception>
#include <memory>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
@ -33,27 +34,27 @@ template< typename StackAllocator, typename Fn >
pull_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, pull_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator salloc,
Fn && fn_, bool preserve_fpu_) : Fn && fn_, bool preserve_fpu_) :
other( nullptr), other( nullptr),
ctx( palloc, salloc, ctx( std::allocator_arg, palloc, salloc,
[=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void { [=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void {
// create synthesized push_coroutine< T > // create synthesized push_coroutine< T >
typename push_coroutine< T >::control_block synthesized_cb( this, ctx); typename push_coroutine< T >::control_block synthesized_cb( this, ctx);
push_coroutine< T > synthesized( & synthesized_cb); push_coroutine< T > synthesized( & synthesized_cb);
other = & synthesized_cb; other = & synthesized_cb;
try { try {
// call coroutine-fn with synthesized push_coroutine as argument // call coroutine-fn with synthesized push_coroutine as argument
fn( synthesized); fn( synthesized);
} catch ( forced_unwind const&) { } catch ( forced_unwind const&) {
// do nothing for unwinding exception // do nothing for unwinding exception
} catch (...) { } catch (...) {
// store other exceptions in exception-pointer // store other exceptions in exception-pointer
except = std::current_exception(); except = std::current_exception();
} }
// set termination flags // set termination flags
state |= static_cast< int >( state_t::complete); state |= static_cast< int >( state_t::complete);
// jump back to ctx // jump back to ctx
other->ctx( preserve_fpu); other->ctx( preserve_fpu);
BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); BOOST_ASSERT_MSG( false, "pull_coroutine is complete");
}), }),
preserve_fpu( preserve_fpu_), preserve_fpu( preserve_fpu_),
state( static_cast< int >( state_t::unwind) ), state( static_cast< int >( state_t::unwind) ),
except() { except() {
@ -109,27 +110,27 @@ template< typename StackAllocator, typename Fn >
pull_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, pull_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator salloc,
Fn && fn_, bool preserve_fpu_) : Fn && fn_, bool preserve_fpu_) :
other( nullptr), other( nullptr),
ctx( palloc, salloc, ctx( std::allocator_arg, palloc, salloc,
[=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void { [=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void {
// create synthesized push_coroutine< T > // create synthesized push_coroutine< T >
typename push_coroutine< T & >::control_block synthesized_cb( this, ctx); typename push_coroutine< T & >::control_block synthesized_cb( this, ctx);
push_coroutine< T & > synthesized( & synthesized_cb); push_coroutine< T & > synthesized( & synthesized_cb);
other = & synthesized_cb; other = & synthesized_cb;
try { try {
// call coroutine-fn with synthesized push_coroutine as argument // call coroutine-fn with synthesized push_coroutine as argument
fn( synthesized); fn( synthesized);
} catch ( forced_unwind const&) { } catch ( forced_unwind const&) {
// do nothing for unwinding exception // do nothing for unwinding exception
} catch (...) { } catch (...) {
// store other exceptions in exception-pointer // store other exceptions in exception-pointer
except = std::current_exception(); except = std::current_exception();
} }
// set termination flags // set termination flags
state |= static_cast< int >( state_t::complete); state |= static_cast< int >( state_t::complete);
// jump back to ctx // jump back to ctx
other->ctx( preserve_fpu); other->ctx( preserve_fpu);
BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); BOOST_ASSERT_MSG( false, "pull_coroutine is complete");
}), }),
preserve_fpu( preserve_fpu_), preserve_fpu( preserve_fpu_),
state( static_cast< int >( state_t::unwind) ), state( static_cast< int >( state_t::unwind) ),
except() { except() {
@ -184,27 +185,27 @@ template< typename StackAllocator, typename Fn >
pull_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, pull_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc,
Fn && fn_, bool preserve_fpu_) : Fn && fn_, bool preserve_fpu_) :
other( nullptr), other( nullptr),
ctx( palloc, salloc, ctx( std::allocator_arg, palloc, salloc,
[=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void { [=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void {
// create synthesized push_coroutine< T > // create synthesized push_coroutine< T >
typename push_coroutine< void >::control_block synthesized_cb( this, ctx); typename push_coroutine< void >::control_block synthesized_cb( this, ctx);
push_coroutine< void > synthesized( & synthesized_cb); push_coroutine< void > synthesized( & synthesized_cb);
other = & synthesized_cb; other = & synthesized_cb;
try { try {
// call coroutine-fn with synthesized push_coroutine as argument // call coroutine-fn with synthesized push_coroutine as argument
fn( synthesized); fn( synthesized);
} catch ( forced_unwind const&) { } catch ( forced_unwind const&) {
// do nothing for unwinding exception // do nothing for unwinding exception
} catch (...) { } catch (...) {
// store other exceptions in exception-pointer // store other exceptions in exception-pointer
except = std::current_exception(); except = std::current_exception();
} }
// set termination flags // set termination flags
state |= static_cast< int >( state_t::complete); state |= static_cast< int >( state_t::complete);
// jump back to ctx // jump back to ctx
other->ctx( preserve_fpu); other->ctx( preserve_fpu);
BOOST_ASSERT_MSG( false, "pull_coroutine is complete"); BOOST_ASSERT_MSG( false, "pull_coroutine is complete");
}), }),
preserve_fpu( preserve_fpu_), preserve_fpu( preserve_fpu_),
state( static_cast< int >( state_t::unwind) ), state( static_cast< int >( state_t::unwind) ),
except() { except() {

View File

@ -9,6 +9,7 @@
#include <algorithm> #include <algorithm>
#include <exception> #include <exception>
#include <memory>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
@ -34,29 +35,29 @@ template< typename StackAllocator, typename Fn >
push_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, push_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator salloc,
Fn && fn_, bool preserve_fpu_) : Fn && fn_, bool preserve_fpu_) :
other( nullptr), other( nullptr),
ctx( palloc, salloc, ctx( std::allocator_arg, palloc, salloc,
[=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void { [=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void {
// create synthesized pull_coroutine< T > // create synthesized pull_coroutine< T >
typename pull_coroutine< T >::control_block synthesized_cb( this, ctx); typename pull_coroutine< T >::control_block synthesized_cb( this, ctx);
pull_coroutine< T > synthesized( & synthesized_cb); pull_coroutine< T > synthesized( & synthesized_cb);
other = & synthesized_cb; other = & synthesized_cb;
// jump back to ctor // jump back to ctor
ctx( preserve_fpu); ctx( preserve_fpu);
try { try {
// call coroutine-fn with synthesized pull_coroutine as argument // call coroutine-fn with synthesized pull_coroutine as argument
fn( synthesized); fn( synthesized);
} catch ( forced_unwind const&) { } catch ( forced_unwind const&) {
// do nothing for unwinding exception // do nothing for unwinding exception
} catch (...) { } catch (...) {
// store other exceptions in exception-pointer // store other exceptions in exception-pointer
except = std::current_exception(); except = std::current_exception();
} }
// set termination flags // set termination flags
state |= static_cast< int >( state_t::complete); state |= static_cast< int >( state_t::complete);
// jump back to ctx // jump back to ctx
other->ctx( preserve_fpu); other->ctx( preserve_fpu);
BOOST_ASSERT_MSG( false, "push_coroutine is complete"); BOOST_ASSERT_MSG( false, "push_coroutine is complete");
}), }),
preserve_fpu( preserve_fpu_), preserve_fpu( preserve_fpu_),
state( static_cast< int >( state_t::unwind) ), state( static_cast< int >( state_t::unwind) ),
except(), except(),
@ -138,29 +139,29 @@ template< typename StackAllocator, typename Fn >
push_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, push_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator salloc,
Fn && fn_, bool preserve_fpu_) : Fn && fn_, bool preserve_fpu_) :
other( nullptr), other( nullptr),
ctx( palloc, salloc, ctx( std::allocator_arg, palloc, salloc,
[=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void { [=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void {
// create synthesized pull_coroutine< T > // create synthesized pull_coroutine< T >
typename pull_coroutine< T & >::control_block synthesized_cb( this, ctx); typename pull_coroutine< T & >::control_block synthesized_cb( this, ctx);
pull_coroutine< T & > synthesized( & synthesized_cb); pull_coroutine< T & > synthesized( & synthesized_cb);
other = & synthesized_cb; other = & synthesized_cb;
// jump back to ctor // jump back to ctor
ctx( preserve_fpu); ctx( preserve_fpu);
try { try {
// call coroutine-fn with synthesized pull_coroutine as argument // call coroutine-fn with synthesized pull_coroutine as argument
fn( synthesized); fn( synthesized);
} catch ( forced_unwind const&) { } catch ( forced_unwind const&) {
// do nothing for unwinding exception // do nothing for unwinding exception
} catch (...) { } catch (...) {
// store other exceptions in exception-pointer // store other exceptions in exception-pointer
except = std::current_exception(); except = std::current_exception();
} }
// set termination flags // set termination flags
state |= static_cast< int >( state_t::complete); state |= static_cast< int >( state_t::complete);
// jump back to ctx // jump back to ctx
other->ctx( preserve_fpu); other->ctx( preserve_fpu);
BOOST_ASSERT_MSG( false, "push_coroutine is complete"); BOOST_ASSERT_MSG( false, "push_coroutine is complete");
}), }),
preserve_fpu( preserve_fpu_), preserve_fpu( preserve_fpu_),
state( static_cast< int >( state_t::unwind) ), state( static_cast< int >( state_t::unwind) ),
except(), except(),
@ -218,29 +219,29 @@ push_coroutine< T & >::control_block::valid() const noexcept {
template< typename StackAllocator, typename Fn > template< typename StackAllocator, typename Fn >
push_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, Fn && fn_, bool preserve_fpu_) : push_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, Fn && fn_, bool preserve_fpu_) :
other( nullptr), other( nullptr),
ctx( palloc, salloc, ctx( std::allocator_arg, palloc, salloc,
[=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void { [=,fn=std::forward< Fn >( fn_),ctx=boost::context::execution_context::current()] () mutable -> void {
// create synthesized pull_coroutine< T > // create synthesized pull_coroutine< T >
typename pull_coroutine< void >::control_block synthesized_cb( this, ctx); typename pull_coroutine< void >::control_block synthesized_cb( this, ctx);
pull_coroutine< void > synthesized( & synthesized_cb); pull_coroutine< void > synthesized( & synthesized_cb);
other = & synthesized_cb; other = & synthesized_cb;
// jump back to ctor // jump back to ctor
ctx( preserve_fpu); ctx( preserve_fpu);
try { try {
// call coroutine-fn with synthesized pull_coroutine as argument // call coroutine-fn with synthesized pull_coroutine as argument
fn( synthesized); fn( synthesized);
} catch ( forced_unwind const&) { } catch ( forced_unwind const&) {
// do nothing for unwinding exception // do nothing for unwinding exception
} catch (...) { } catch (...) {
// store other exceptions in exception-pointer // store other exceptions in exception-pointer
except = std::current_exception(); except = std::current_exception();
} }
// set termination flags // set termination flags
state |= static_cast< int >( state_t::complete); state |= static_cast< int >( state_t::complete);
// jump back to ctx // jump back to ctx
other->ctx( preserve_fpu); other->ctx( preserve_fpu);
BOOST_ASSERT_MSG( false, "push_coroutine is complete"); BOOST_ASSERT_MSG( false, "push_coroutine is complete");
}), }),
preserve_fpu( preserve_fpu_), preserve_fpu( preserve_fpu_),
state( static_cast< int >( state_t::unwind) ), state( static_cast< int >( state_t::unwind) ),
except() { except() {