2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-17 13:42:21 +00:00

fix using intruisve::list<>

This commit is contained in:
Oliver Kowalke
2015-09-10 18:08:10 +02:00
parent 2173200c14
commit d3843efbe0
17 changed files with 184 additions and 157 deletions

View File

@@ -39,10 +39,10 @@ enum class cv_status {
class BOOST_FIBERS_DECL condition {
private:
typedef detail::wait_queue< context > wqueue_t;
typedef detail::wait_queue< context > wait_queue_t;
detail::spinlock splk_;
wqueue_t waiting_;
wait_queue_t wait_queue_;
public:
condition();
@@ -73,7 +73,7 @@ public:
// store this fiber in waiting-queue
// in order notify (resume) this fiber later
BOOST_ASSERT( ! f->wait_is_linked() );
waiting_.push_back( * f);
wait_queue_.push_back( * f);
// unlock external
lt.unlock();
@@ -87,7 +87,7 @@ public:
lt.lock();
} catch (...) {
detail::spinlock_lock lk( splk_);
detail::erase_and_dispose( waiting_, f);
f->wait_unlink();
throw;
}
}
@@ -104,7 +104,7 @@ public:
// store this fiber in waiting-queue
// in order notify (resume) this fiber later
BOOST_ASSERT( ! f->wait_is_linked() );
waiting_.push_back( * f);
wait_queue_.push_back( * f);
// unlock external
lt.unlock();
@@ -116,7 +116,7 @@ public:
// this fiber was not notified before timeout
// lock spinlock again
detail::spinlock_lock lk( splk_);
detail::erase_and_dispose( waiting_, f);
f->wait_unlink();
status = cv_status::timeout;
}
@@ -125,7 +125,7 @@ public:
lt.lock();
} catch (...) {
detail::spinlock_lock lk( splk_);
detail::erase_and_dispose( waiting_, f);
f->wait_unlink();
throw;
}

View File

@@ -43,9 +43,7 @@ class fiber_properties;
class scheduler;
struct sched_algorithm;
class BOOST_FIBERS_DECL context : public detail::state_hook,
public detail::yield_hook,
public detail::wait_hook {
class BOOST_FIBERS_DECL context {
private:
enum class fiber_status {
ready = 0,
@@ -99,7 +97,7 @@ private:
scheduler * scheduler_;
boost::context::execution_context ctx_;
fss_data_t fss_data_;
std::vector< context * > waiting_;
std::vector< context * > wait_queue_;
std::exception_ptr except_;
std::chrono::steady_clock::time_point tp_;
fiber_properties * properties_;
@@ -168,6 +166,11 @@ public:
}
};
detail::runnable_hook runnable_hook_;
detail::ready_hook ready_hook_;
detail::sleep_hook sleep_hook_;
detail::wait_hook wait_hook_;
static context * active() noexcept;
static void active( context * active) noexcept;
@@ -181,7 +184,7 @@ public:
scheduler_( nullptr),
ctx_( boost::context::execution_context::current() ),
fss_data_(),
waiting_(),
wait_queue_(),
except_(),
tp_( (std::chrono::steady_clock::time_point::max)() ),
properties_( nullptr) {
@@ -225,7 +228,7 @@ public:
BOOST_ASSERT_MSG( false, "fiber already terminated");
}),
fss_data_(),
waiting_(),
wait_queue_(),
except_(),
tp_( (std::chrono::steady_clock::time_point::max)() ),
properties_( nullptr) {
@@ -401,16 +404,24 @@ public:
std::chrono::steady_clock::duration do_wait_interval() noexcept;
bool state_is_linked() {
return detail::state_hook::is_linked();
bool runnable_is_linked() {
return runnable_hook_.is_linked();
}
bool yield_is_linked() {
return detail::yield_hook::is_linked();
bool ready_is_linked() {
return ready_hook_.is_linked();
}
bool sleep_is_linked() {
return sleep_hook_.is_linked();
}
bool wait_is_linked() {
return detail::wait_hook::is_linked();
return wait_hook_.is_linked();
}
void wait_unlink() {
wait_hook_.unlink();
}
friend void intrusive_ptr_add_ref( context * f) {

View File

@@ -20,50 +20,57 @@ namespace boost {
namespace fibers {
namespace detail {
struct state_tag;
typedef intrusive::list_base_hook<
intrusive::tag< state_tag >,
struct runnable_tag;
typedef intrusive::list_member_hook<
intrusive::tag< runnable_tag >,
intrusive::link_mode<
intrusive::safe_link
>
> state_hook;
> runnable_hook;
template< typename T >
using state_queue = intrusive::list<
using runnable_queue = intrusive::list<
T,
intrusive::base_hook< state_hook > >;
intrusive::member_hook< T, runnable_hook, & T::runnable_hook_ > >;
struct yield_tag;
typedef intrusive::list_base_hook<
intrusive::tag< yield_tag >,
struct ready_tag;
typedef intrusive::list_member_hook<
intrusive::tag< ready_tag >,
intrusive::link_mode<
intrusive::safe_link
>
> yield_hook;
> ready_hook;
template< typename T >
using yield_queue = intrusive::list<
using ready_queue = intrusive::list<
T,
intrusive::base_hook< yield_hook >,
intrusive::member_hook< T, ready_hook, & T::ready_hook_ >,
intrusive::constant_time_size< false > >;
struct sleep_tag;
typedef intrusive::list_member_hook<
intrusive::tag< sleep_tag >,
intrusive::link_mode<
intrusive::safe_link
>
> sleep_hook;
template< typename T >
using sleep_queue = intrusive::list<
T,
intrusive::member_hook< T, sleep_hook, & T::sleep_hook_ >,
intrusive::constant_time_size< false > >;
struct wait_tag;
typedef intrusive::list_base_hook<
typedef intrusive::list_member_hook<
intrusive::tag< wait_tag >,
intrusive::link_mode<
intrusive::safe_link
intrusive::auto_unlink
>
> wait_hook;
template< typename T >
using wait_queue = intrusive::list<
T,
intrusive::base_hook< wait_hook >,
intrusive::member_hook< T, wait_hook, & T::wait_hook_ >,
intrusive::constant_time_size< false > >;
template< typename Lst, typename Ctx >
void erase_and_dispose( Lst & lst, Ctx * ctx){
typename Lst::iterator i( Lst::s_iterator_to( * ctx) );
lst.erase_and_dispose( i, []( Ctx * ctx){ intrusive_ptr_release( ctx); });
}
}}}
#ifdef BOOST_HAS_ABI_HEADERS

View File

@@ -28,12 +28,12 @@ private:
unlocked
};
typedef detail::wait_queue< context > wqueue_t;
typedef detail::wait_queue< context > wait_queue_t;
detail::spinlock splk_;
mutex_status state_;
context::id owner_;
wqueue_t waiting_;
wait_queue_t wait_queue_;
bool lock_if_unlocked_();

View File

@@ -32,13 +32,13 @@ private:
unlocked
};
typedef detail::wait_queue< context > wqueue_t;
typedef detail::wait_queue< context > wait_queue_t;
detail::spinlock splk_;
mutex_status state_;
context::id owner_;
std::size_t count_;
wqueue_t waiting_;
wait_queue_t wait_queue_;
bool lock_if_unlocked_();

View File

@@ -34,13 +34,13 @@ private:
unlocked
};
typedef detail::wait_queue< context > wqueue_t;
typedef detail::wait_queue< context > wait_queue_t;
detail::spinlock splk_;
mutex_status state_;
context::id owner_;
std::size_t count_;
wqueue_t waiting_;
wait_queue_t wait_queue_;
bool lock_if_unlocked_();

View File

@@ -26,9 +26,9 @@ class context;
class BOOST_FIBERS_DECL round_robin : public sched_algorithm {
private:
typedef detail::state_queue< context > rqueue_t;
typedef detail::runnable_queue< context > runnable_queue_t;
rqueue_t rqueue_;
runnable_queue_t runnable_queue_;
public:
virtual void awakened( context *);

View File

@@ -9,7 +9,7 @@
#include <cstddef>
#include <chrono>
#include <memory>
#include <mutex>
#include <vector>
#include <boost/assert.hpp>
#include <boost/config.hpp>
@@ -32,15 +32,15 @@ struct sched_algorithm;
class BOOST_FIBERS_DECL scheduler {
private:
typedef detail::state_queue< context > tqueue_t;
typedef detail::state_queue< context > wqueue_t;
typedef detail::yield_queue< context > yqueue_t;
typedef detail::ready_queue< context > ready_queue_t;
typedef detail::sleep_queue< context > sleep_queue_t;
typedef std::vector< context * > terminated_queue_t;
std::unique_ptr< sched_algorithm > sched_algo_;
context * main_context_;
wqueue_t wqueue_;
tqueue_t tqueue_;
yqueue_t yqueue_;
ready_queue_t ready_queue_;
sleep_queue_t sleep_queue_;
terminated_queue_t terminated_queue_;
std::chrono::steady_clock::duration wait_interval_;
void resume_( context *, context *);
@@ -67,7 +67,7 @@ public:
void join( context *,context *);
std::size_t ready_fibers() const noexcept;
size_t ready_fibers() const noexcept;
void set_sched_algo( std::unique_ptr< sched_algorithm >);

View File

@@ -31,12 +31,12 @@ private:
unlocked
};
typedef detail::wait_queue< context > wqueue_t;
typedef detail::wait_queue< context > wait_queue_t;
detail::spinlock splk_;
mutex_status state_;
context::id owner_;
wqueue_t waiting_;
wait_queue_t wait_queue_;
bool lock_if_unlocked_();