From 7a794647ae558e0fb8c7b4af549c303dbdb5ff9f Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Wed, 16 Sep 2015 22:17:01 +0200 Subject: [PATCH] replace context::terminated_is_linked() by context::is_terminated() - context::terminated_is_linked() might be missleading because this state is transient - if the context is pushed to the terminated-queue, context::terminated_is_linked() returns true, if the context is removed from terminated-queue context::terminated_is_linked() returns false - new flag flag_terminated intoduced - flag_terminated will be set in context::set_terminated_(), which will be called for worker context' in the lambda --- include/boost/fiber/context.hpp | 6 ++++-- src/context.cpp | 7 +------ src/scheduler.cpp | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/boost/fiber/context.hpp b/include/boost/fiber/context.hpp index 0773f6e2..1fffb56d 100644 --- a/include/boost/fiber/context.hpp +++ b/include/boost/fiber/context.hpp @@ -248,12 +248,14 @@ public: return 0 != ( flags_ & flag_worker_context); } + bool is_terminated() const noexcept { + return 0 != ( flags_ & flag_terminated); + } + bool wait_is_linked(); bool ready_is_linked(); - bool terminated_is_linked(); - void wait_unlink(); friend void intrusive_ptr_add_ref( context * ctx) { diff --git a/src/context.cpp b/src/context.cpp index ecd2d7c3..276e4ad1 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -113,7 +113,7 @@ context::resume() { void context::release() noexcept { - BOOST_ASSERT( terminated_is_linked() ); + BOOST_ASSERT( is_terminated() ); // notify all waiting fibers wait_queue_t::iterator e = wait_queue_.end(); @@ -151,11 +151,6 @@ context::ready_is_linked() { return ready_hook_.is_linked(); } -bool -context::terminated_is_linked() { - return terminated_hook_.is_linked(); -} - void context::wait_unlink() { wait_hook_.unlink(); diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 219c8cde..84384425 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -132,7 +132,7 @@ void scheduler::set_ready( context * ctx) noexcept { BOOST_ASSERT( nullptr != ctx); BOOST_ASSERT( ! ctx->ready_is_linked() ); - BOOST_ASSERT( ! ctx->terminated_is_linked() ); + BOOST_ASSERT( ! ctx->is_terminated() ); BOOST_ASSERT( ! ctx->wait_is_linked() ); // set the scheduler for new fiber context ctx->set_scheduler( this); @@ -143,8 +143,8 @@ scheduler::set_ready( context * ctx) noexcept { void scheduler::set_terminated( context * ctx) noexcept { BOOST_ASSERT( nullptr != ctx); + BOOST_ASSERT( ctx->is_terminated() ); BOOST_ASSERT( ! ctx->ready_is_linked() ); - BOOST_ASSERT( ! ctx->terminated_is_linked() ); BOOST_ASSERT( ! ctx->wait_is_linked() ); terminated_queue_.push_back( * ctx); }