2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-01-31 20:22:07 +00:00

Use std::shared_ptr and std::make_shared for promise_handler.

Publish promise_handler::promise_ptr and use it in asio_handler_invoke() for
consistency.
This commit is contained in:
Nat Goodspeed
2015-09-03 08:47:25 -04:00
parent 64b56e2200
commit bcdb555821
2 changed files with 16 additions and 9 deletions

View File

@@ -33,14 +33,14 @@ namespace detail {
//[fibers_asio_promise_handler_base
template< typename T >
class promise_handler_base {
private:
typedef boost::shared_ptr< boost::fibers::promise< T > > promise_ptr;
public:
typedef std::shared_ptr< boost::fibers::promise< T > > promise_ptr;
// Construct from any promise_completion_token subclass special value.
template< typename Allocator >
promise_handler_base( boost::fibers::asio::promise_completion_token< Allocator > const& pct) :
promise_( new boost::fibers::promise< T >( std::allocator_arg, pct.get_allocator() ) )
promise_( std::make_shared< boost::fibers::promise< T > >(
std::allocator_arg, pct.get_allocator() ) )
//<-
, ecp_( pct.ec_)
//->
@@ -112,6 +112,7 @@ public:
}
}
//<-
using promise_handler_base< T >::promise_ptr;
using promise_handler_base< T >::get_promise;
//->
};
@@ -140,6 +141,7 @@ public:
}
}
using promise_handler_base< void >::promise_ptr;
using promise_handler_base< void >::get_promise;
};
@@ -152,7 +154,8 @@ namespace detail {
// from the handler are propagated back to the caller via the future.
template< typename Function, typename T >
void asio_handler_invoke( Function f, fibers::asio::detail::promise_handler< T > * h) {
boost::shared_ptr< boost::fibers::promise< T > > p( h->get_promise() );
typename fibers::asio::detail::promise_handler< T >::promise_ptr
p( h->get_promise() );
try {
f();
} catch (...) {

View File

@@ -65,13 +65,15 @@ private:
// Handler type specialisation for yield for a nullary callback.
template< typename Allocator, typename ReturnType >
struct handler_type< boost::fibers::asio::yield_t< Allocator >, ReturnType() > {
struct handler_type< boost::fibers::asio::yield_t< Allocator >,
ReturnType() > {
typedef boost::fibers::asio::detail::yield_handler< void > type;
};
// Handler type specialisation for yield for a single-argument callback.
template< typename Allocator, typename ReturnType, typename Arg1 >
struct handler_type< boost::fibers::asio::yield_t< Allocator >, ReturnType( Arg1) > {
struct handler_type< boost::fibers::asio::yield_t< Allocator >,
ReturnType( Arg1) > {
typedef fibers::asio::detail::yield_handler< Arg1 > type;
};
@@ -80,7 +82,8 @@ struct handler_type< boost::fibers::asio::yield_t< Allocator >, ReturnType( Arg1
// error_code indicating error will be conveyed to consumer code via an
// exception. Normal return implies (! error_code).
template< typename Allocator, typename ReturnType >
struct handler_type< boost::fibers::asio::yield_t< Allocator >, ReturnType( boost::system::error_code) > {
struct handler_type< boost::fibers::asio::yield_t< Allocator >,
ReturnType( boost::system::error_code) > {
typedef fibers::asio::detail::yield_handler< void > type;
};
@@ -91,7 +94,8 @@ struct handler_type< boost::fibers::asio::yield_t< Allocator >, ReturnType( boos
// error_code).
//[asio_handler_type
template< typename Allocator, typename ReturnType, typename Arg2 >
struct handler_type< boost::fibers::asio::yield_t< Allocator >, ReturnType( boost::system::error_code, Arg2) > {
struct handler_type< boost::fibers::asio::yield_t< Allocator >,
ReturnType( boost::system::error_code, Arg2) > {
typedef fibers::asio::detail::yield_handler< Arg2 > type;
};
//]