update boost
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/config.hpp>
|
||||
@@ -43,6 +44,7 @@
|
||||
#include <boost/fiber/properties.hpp>
|
||||
#include <boost/fiber/segmented_stack.hpp>
|
||||
#include <boost/fiber/type.hpp>
|
||||
#include <boost/fiber/waker.hpp>
|
||||
|
||||
#ifdef BOOST_HAS_ABI_HEADERS
|
||||
# include BOOST_ABI_PREFIX
|
||||
@@ -62,31 +64,6 @@ class scheduler;
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct wait_tag;
|
||||
typedef intrusive::list_member_hook<
|
||||
intrusive::tag< wait_tag >,
|
||||
intrusive::link_mode<
|
||||
intrusive::auto_unlink
|
||||
>
|
||||
> wait_hook;
|
||||
// declaration of the functor that converts between
|
||||
// the context class and the wait-hook
|
||||
struct wait_functor {
|
||||
// required types
|
||||
typedef wait_hook hook_type;
|
||||
typedef hook_type * hook_ptr;
|
||||
typedef const hook_type * const_hook_ptr;
|
||||
typedef context value_type;
|
||||
typedef value_type * pointer;
|
||||
typedef const value_type * const_pointer;
|
||||
|
||||
// required static functions
|
||||
static hook_ptr to_hook_ptr( value_type &value);
|
||||
static const_hook_ptr to_hook_ptr( value_type const& value);
|
||||
static pointer to_value_ptr( hook_ptr n);
|
||||
static const_pointer to_value_ptr( const_hook_ptr n);
|
||||
};
|
||||
|
||||
struct ready_tag;
|
||||
typedef intrusive::list_member_hook<
|
||||
intrusive::tag< ready_tag >,
|
||||
@@ -130,13 +107,6 @@ typedef intrusive::slist_member_hook<
|
||||
}
|
||||
|
||||
class BOOST_FIBERS_DECL context {
|
||||
public:
|
||||
typedef intrusive::list<
|
||||
context,
|
||||
intrusive::function_hook< detail::wait_functor >,
|
||||
intrusive::constant_time_size< false >
|
||||
> wait_queue_t;
|
||||
|
||||
private:
|
||||
friend class dispatcher_context;
|
||||
friend class main_context;
|
||||
@@ -147,13 +117,12 @@ private:
|
||||
void * vp{ nullptr };
|
||||
detail::fss_cleanup_function::ptr_t cleanup_function{};
|
||||
|
||||
fss_data() noexcept {
|
||||
}
|
||||
fss_data() = default;
|
||||
|
||||
fss_data( void * vp_,
|
||||
detail::fss_cleanup_function::ptr_t const& fn) noexcept :
|
||||
detail::fss_cleanup_function::ptr_t fn) noexcept :
|
||||
vp( vp_),
|
||||
cleanup_function( fn) {
|
||||
cleanup_function(std::move( fn)) {
|
||||
BOOST_ASSERT( cleanup_function);
|
||||
}
|
||||
|
||||
@@ -174,16 +143,16 @@ private:
|
||||
#endif
|
||||
detail::spinlock splk_{};
|
||||
bool terminated_{ false };
|
||||
wait_queue_t wait_queue_{};
|
||||
wait_queue wait_queue_{};
|
||||
public:
|
||||
detail::wait_hook wait_hook_{};
|
||||
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
|
||||
std::atomic< std::intptr_t > twstatus{ 0 };
|
||||
std::atomic<size_t> waker_epoch_{ 0 };
|
||||
#endif
|
||||
private:
|
||||
scheduler * scheduler_{ nullptr };
|
||||
fss_data_t fss_data_{};
|
||||
detail::sleep_hook sleep_hook_{};
|
||||
waker sleep_waker_{};
|
||||
detail::ready_hook ready_hook_{};
|
||||
detail::terminated_hook terminated_hook_{};
|
||||
detail::worker_hook worker_hook_{};
|
||||
@@ -241,9 +210,8 @@ public:
|
||||
operator<<( std::basic_ostream< charT, traitsT > & os, id const& other) {
|
||||
if ( nullptr != other.impl_) {
|
||||
return os << other.impl_;
|
||||
} else {
|
||||
return os << "{not-valid}";
|
||||
}
|
||||
return os << "{not-valid}";
|
||||
}
|
||||
|
||||
explicit operator bool() const noexcept {
|
||||
@@ -264,11 +232,20 @@ public:
|
||||
context & operator=( context const&) = delete;
|
||||
context & operator=( context &&) = delete;
|
||||
|
||||
#if !defined(BOOST_EMBTC)
|
||||
|
||||
friend bool
|
||||
operator==( context const& lhs, context const& rhs) noexcept {
|
||||
return & lhs == & rhs;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
friend bool
|
||||
operator==( context const& lhs, context const& rhs) noexcept;
|
||||
|
||||
#endif
|
||||
|
||||
virtual ~context();
|
||||
|
||||
scheduler * get_scheduler() const noexcept {
|
||||
@@ -278,8 +255,7 @@ public:
|
||||
id get_id() const noexcept;
|
||||
|
||||
bool is_resumable() const noexcept {
|
||||
if ( c_) return true;
|
||||
else return false;
|
||||
return static_cast<bool>(c_);
|
||||
}
|
||||
|
||||
void resume() noexcept;
|
||||
@@ -298,7 +274,15 @@ public:
|
||||
|
||||
bool wait_until( std::chrono::steady_clock::time_point const&) noexcept;
|
||||
bool wait_until( std::chrono::steady_clock::time_point const&,
|
||||
detail::spinlock_lock &) noexcept;
|
||||
detail::spinlock_lock &,
|
||||
waker &&) noexcept;
|
||||
|
||||
bool wake(const size_t) noexcept;
|
||||
|
||||
waker create_waker() noexcept {
|
||||
// this operation makes all previously created wakers to be outdated
|
||||
return { this, ++waker_epoch_ };
|
||||
}
|
||||
|
||||
void schedule( context *) noexcept;
|
||||
|
||||
@@ -334,8 +318,6 @@ public:
|
||||
|
||||
bool terminated_is_linked() const noexcept;
|
||||
|
||||
bool wait_is_linked() const noexcept;
|
||||
|
||||
template< typename List >
|
||||
void worker_link( List & lst) noexcept {
|
||||
static_assert( std::is_same< typename List::value_traits::hook_type, detail::worker_hook >::value, "not a worker-queue");
|
||||
@@ -371,25 +353,18 @@ public:
|
||||
lst.push_back( * this);
|
||||
}
|
||||
|
||||
template< typename List >
|
||||
void wait_link( List & lst) noexcept {
|
||||
static_assert( std::is_same< typename List::value_traits::hook_type, detail::wait_hook >::value, "not a wait-queue");
|
||||
BOOST_ASSERT( ! wait_is_linked() );
|
||||
lst.push_back( * this);
|
||||
}
|
||||
|
||||
void worker_unlink() noexcept;
|
||||
|
||||
void ready_unlink() noexcept;
|
||||
|
||||
void sleep_unlink() noexcept;
|
||||
|
||||
void wait_unlink() noexcept;
|
||||
|
||||
void detach() noexcept;
|
||||
|
||||
void attach( context *) noexcept;
|
||||
|
||||
#if !defined(BOOST_EMBTC)
|
||||
|
||||
friend void intrusive_ptr_add_ref( context * ctx) noexcept {
|
||||
BOOST_ASSERT( nullptr != ctx);
|
||||
ctx->use_count_.fetch_add( 1, std::memory_order_relaxed);
|
||||
@@ -406,8 +381,42 @@ public:
|
||||
std::move( c).resume();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
friend void intrusive_ptr_add_ref( context * ctx) noexcept;
|
||||
friend void intrusive_ptr_release( context * ctx) noexcept;
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#if defined(BOOST_EMBTC)
|
||||
|
||||
inline bool
|
||||
operator==( context const& lhs, context const& rhs) noexcept {
|
||||
return & lhs == & rhs;
|
||||
}
|
||||
|
||||
inline void intrusive_ptr_add_ref( context * ctx) noexcept {
|
||||
BOOST_ASSERT( nullptr != ctx);
|
||||
ctx->use_count_.fetch_add( 1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
inline void intrusive_ptr_release( context * ctx) noexcept {
|
||||
BOOST_ASSERT( nullptr != ctx);
|
||||
if ( 1 == ctx->use_count_.fetch_sub( 1, std::memory_order_release) ) {
|
||||
std::atomic_thread_fence( std::memory_order_acquire);
|
||||
boost::context::fiber c = std::move( ctx->c_);
|
||||
// destruct context
|
||||
ctx->~context();
|
||||
// deallocated stack
|
||||
std::move( c).resume();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline
|
||||
bool operator<( context const& l, context const& r) noexcept {
|
||||
return l.get_id() < r.get_id();
|
||||
@@ -443,22 +452,35 @@ private:
|
||||
public:
|
||||
template< typename StackAlloc >
|
||||
worker_context( launch policy,
|
||||
fiber_properties* properties,
|
||||
boost::context::preallocated const& palloc, StackAlloc && salloc,
|
||||
Fn && fn, Arg ... arg) :
|
||||
context{ 1, type::worker_context, policy },
|
||||
fn_( std::forward< Fn >( fn) ),
|
||||
arg_( std::forward< Arg >( arg) ... ) {
|
||||
if ( properties != nullptr ) {
|
||||
set_properties(properties);
|
||||
properties->set_context(this);
|
||||
}
|
||||
c_ = boost::context::fiber{ std::allocator_arg, palloc, std::forward< StackAlloc >( salloc),
|
||||
std::bind( & worker_context::run_, this, std::placeholders::_1) };
|
||||
#if (defined(BOOST_USE_UCONTEXT)||defined(BOOST_USE_WINFIB))
|
||||
c_ = std::move( c_).resume();
|
||||
#endif
|
||||
}
|
||||
|
||||
template< typename StackAlloc >
|
||||
worker_context( launch policy,
|
||||
boost::context::preallocated const& palloc, StackAlloc && salloc,
|
||||
Fn && fn, Arg ... arg) :
|
||||
worker_context( policy, palloc, salloc, nullptr, std::forward<Fn>( fn ), std::forward<Arg>( arg ) ... ){
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template< typename StackAlloc, typename Fn, typename ... Arg >
|
||||
static intrusive_ptr< context > make_worker_context( launch policy,
|
||||
static intrusive_ptr< context > make_worker_context_with_properties( launch policy,
|
||||
fiber_properties* properties,
|
||||
StackAlloc && salloc,
|
||||
Fn && fn, Arg ... arg) {
|
||||
typedef worker_context< Fn, Arg ... > context_t;
|
||||
@@ -475,35 +497,23 @@ static intrusive_ptr< context > make_worker_context( launch policy,
|
||||
return intrusive_ptr< context >{
|
||||
new ( storage) context_t{
|
||||
policy,
|
||||
properties,
|
||||
boost::context::preallocated{ storage, size, sctx },
|
||||
std::forward< StackAlloc >( salloc),
|
||||
std::forward< Fn >( fn),
|
||||
std::forward< Arg >( arg) ... } };
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
inline
|
||||
wait_functor::hook_ptr wait_functor::to_hook_ptr( wait_functor::value_type & value) {
|
||||
return & value.wait_hook_;
|
||||
template< typename StackAlloc, typename Fn, typename ... Arg >
|
||||
static intrusive_ptr< context > make_worker_context( launch policy,
|
||||
StackAlloc && salloc,
|
||||
Fn && fn, Arg ... arg){
|
||||
return make_worker_context_with_properties( policy, nullptr, std::forward<StackAlloc>(salloc),
|
||||
std::forward<Fn>( fn ), std::forward<Arg>( arg ) ... );
|
||||
}
|
||||
|
||||
inline
|
||||
wait_functor::const_hook_ptr wait_functor::to_hook_ptr( wait_functor::value_type const& value) {
|
||||
return & value.wait_hook_;
|
||||
}
|
||||
|
||||
inline
|
||||
wait_functor::pointer wait_functor::to_value_ptr( wait_functor::hook_ptr n) {
|
||||
return intrusive::get_parent_from_member< context >( n, & context::wait_hook_);
|
||||
}
|
||||
|
||||
inline
|
||||
wait_functor::const_pointer wait_functor::to_value_ptr( wait_functor::const_hook_ptr n) {
|
||||
return intrusive::get_parent_from_member< context >( n, & context::wait_hook_);
|
||||
}
|
||||
|
||||
}}}
|
||||
}}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
|
||||
Reference in New Issue
Block a user