2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-20 02:32:19 +00:00

BOOST_FIBERS_NO_ATOMICS disables remote-ready-queue

- remote-ready-queu is only used to signal the readyness of a fiber
  by other threads (that to not own the signaled fiber)
This commit is contained in:
Oliver Kowalke
2016-10-22 11:12:33 +02:00
parent b1f609ea60
commit 88ce345ec3
3 changed files with 22 additions and 1 deletions

View File

@@ -50,7 +50,9 @@ public:
context, detail::ready_hook, & context::ready_hook_ >,
intrusive::constant_time_size< false > > ready_queue_t;
private:
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
typedef std::vector< context * > remote_ready_queue_t;
#endif
typedef intrusive::set<
context,
intrusive::member_hook<
@@ -77,20 +79,24 @@ private:
worker_queue_t worker_queue_{};
// terminated-queue contains context' which have been terminated
terminated_queue_t terminated_queue_{};
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
// remote ready-queue contains context' signaled by schedulers
// running in other threads
remote_ready_queue_t remote_ready_queue_{};
std::mutex remote_ready_mtx_{};
#endif
// sleep-queue cotnains context' whic hahve been called
// scheduler::wait_until()
sleep_queue_t sleep_queue_{};
bool shutdown_{ false };
std::mutex remote_ready_mtx_{};
context * get_next_() noexcept;
void release_terminated_() noexcept;
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
void remote_ready2ready_() noexcept;
#endif
void sleep2ready_() noexcept;
@@ -104,7 +110,9 @@ public:
void set_ready( context *) noexcept;
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
void set_remote_ready( context *) noexcept;
#endif
#if (BOOST_EXECUTION_CONTEXT==1)
void dispatch() noexcept;

View File

@@ -391,6 +391,7 @@ context::set_ready( context * ctx) noexcept {
BOOST_ASSERT( this != ctx);
BOOST_ASSERT( nullptr != scheduler_ );
BOOST_ASSERT( nullptr != ctx->scheduler_ );
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
// FIXME: comparing scheduler address' must be synchronized?
// what if ctx is migrated between threads
// (other scheduler assigned)
@@ -401,6 +402,10 @@ context::set_ready( context * ctx) noexcept {
// remote
ctx->scheduler_->set_remote_ready( ctx);
}
#else
BOOST_ASSERT( scheduler_ == ctx->scheduler_ );
scheduler_->set_ready( ctx);
#endif
}
void *

View File

@@ -53,6 +53,7 @@ scheduler::release_terminated_() noexcept {
}
}
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
void
scheduler::remote_ready2ready_() noexcept {
// protect for concurrent access
@@ -64,6 +65,7 @@ scheduler::remote_ready2ready_() noexcept {
}
remote_ready_queue_.clear();
}
#endif
void
scheduler::sleep2ready_() noexcept {
@@ -112,7 +114,9 @@ scheduler::~scheduler() {
// no context' in worker-queue
BOOST_ASSERT( worker_queue_.empty() );
BOOST_ASSERT( terminated_queue_.empty() );
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
BOOST_ASSERT( remote_ready_queue_.empty() );
#endif
BOOST_ASSERT( sleep_queue_.empty() );
// set active context to nullptr
context::reset_active();
@@ -142,8 +146,10 @@ scheduler::dispatch() noexcept {
}
// release terminated context'
release_terminated_();
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
// get context' from remote ready-queue
remote_ready2ready_();
#endif
// get sleeping context'
sleep2ready_();
// get next ready context
@@ -197,6 +203,7 @@ scheduler::set_ready( context * ctx) noexcept {
algo_->awakened( ctx);
}
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
void
scheduler::set_remote_ready( context * ctx) noexcept {
BOOST_ASSERT( nullptr != ctx);
@@ -216,6 +223,7 @@ scheduler::set_remote_ready( context * ctx) noexcept {
// notify scheduler
algo_->notify();
}
#endif
#if (BOOST_EXECUTION_CONTEXT==1)
void