diff --git a/examples/priority.cpp b/examples/priority.cpp index 2b861af1..8dae6419 100644 --- a/examples/priority.cpp +++ b/examples/priority.cpp @@ -70,7 +70,7 @@ private: //[priority_scheduler class priority_scheduler : public boost::fibers::sched_algorithm_with_properties< priority_props > { private: - typedef boost::fibers::detail::state_queue< boost::fibers::context > rqueue_t; + typedef boost::fibers::detail::runnable_queue< boost::fibers::context > rqueue_t; rqueue_t rqueue_; diff --git a/include/boost/fiber/condition.hpp b/include/boost/fiber/condition.hpp index 182c1419..929499c4 100644 --- a/include/boost/fiber/condition.hpp +++ b/include/boost/fiber/condition.hpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include #include @@ -41,8 +41,8 @@ class BOOST_FIBERS_DECL condition { private: typedef detail::wait_queue< context > wait_queue_t; - detail::spinlock splk_; - wait_queue_t wait_queue_; + detail::spinlock splk_; + wait_queue_t wait_queue_; public: condition(); @@ -79,6 +79,8 @@ public: // unlock external lt.unlock(); + // check if fiber was interrupted + this_fiber::interruption_point(); // suspend this fiber f->do_schedule(); @@ -92,9 +94,10 @@ public: } template< typename LockType, typename Clock, typename Duration > - cv_status wait_until( LockType & lt, std::chrono::time_point< Clock, Duration > const& timeout_time) { + cv_status wait_until( LockType & lt, std::chrono::time_point< Clock, Duration > const& timeout_time_) { cv_status status = cv_status::no_timeout; - + std::chrono::steady_clock::time_point timeout_time( + detail::clock_cast( timeout_time_) ); context * f( context::active() ); try { // lock spinlock @@ -109,6 +112,8 @@ public: // unlock external lt.unlock(); + // check if fiber was interrupted + this_fiber::interruption_point(); // suspend this fiber if ( ! f->do_wait_until( timeout_time) ) { // this fiber was not notified before timeout diff --git a/include/boost/fiber/context.hpp b/include/boost/fiber/context.hpp index 3541d76c..a5df3796 100644 --- a/include/boost/fiber/context.hpp +++ b/include/boost/fiber/context.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include @@ -104,8 +104,6 @@ private: std::chrono::steady_clock::time_point tp_; fiber_properties * properties_; - bool do_wait_until_( std::chrono::steady_clock::time_point const&); - protected: virtual void deallocate() { } @@ -324,7 +322,7 @@ public: fiber_status previous = state_; state_ = fiber_status::waiting; #endif - BOOST_ASSERT( fiber_status::running == previous); + BOOST_ASSERT( fiber_status::waiting == previous || fiber_status::running == previous); (void)previous; } @@ -374,12 +372,7 @@ public: void do_schedule(); - template< typename Clock, typename Duration > - bool do_wait_until( std::chrono::time_point< Clock, Duration > const& timeout_time_) { - std::chrono::steady_clock::time_point timeout_time( - detail::convert_tp( timeout_time_) ); - return do_wait_until_( timeout_time); - } + bool do_wait_until( std::chrono::steady_clock::time_point const&); void do_yield(); @@ -391,13 +384,6 @@ public: void do_set_sched_algo( std::unique_ptr< sched_algorithm >); - template< typename Rep, typename Period > - void do_wait_interval( std::chrono::duration< Rep, Period > const& wait_interval) noexcept { - // wait_interval_( wait_interval); FIXME - } - - std::chrono::steady_clock::duration do_wait_interval() noexcept; - bool runnable_is_linked() { return runnable_hook_.is_linked(); } @@ -410,6 +396,10 @@ public: return sleep_hook_.is_linked(); } + void sleep_unlink() { + sleep_hook_.unlink(); + } + bool wait_is_linked() { return wait_hook_.is_linked(); } diff --git a/include/boost/fiber/detail/convert.hpp b/include/boost/fiber/detail/clock_cast.hpp similarity index 63% rename from include/boost/fiber/detail/convert.hpp rename to include/boost/fiber/detail/clock_cast.hpp index 4a937375..f7d78a6b 100644 --- a/include/boost/fiber/detail/convert.hpp +++ b/include/boost/fiber/detail/clock_cast.hpp @@ -4,8 +4,8 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_FIBERS_DETAIL_CONVERT_H -#define BOOST_FIBERS_DETAIL_CONVERT_H +#ifndef BOOST_FIBERS_DETAIL_CLOCK_CAST_H +#define BOOST_FIBERS_DETAIL_CLOCK_CAST_H #include @@ -22,12 +22,14 @@ namespace fibers { namespace detail { inline -std::chrono::steady_clock::time_point convert_tp( std::chrono::steady_clock::time_point const& timeout_time) noexcept { +std::chrono::steady_clock::time_point clock_cast( + std::chrono::steady_clock::time_point const& timeout_time) noexcept { return timeout_time; } template< typename Clock, typename Duration > -std::chrono::steady_clock::time_point convert_tp( std::chrono::time_point< Clock, Duration > const& timeout_time) { +std::chrono::steady_clock::time_point clock_cast( + std::chrono::time_point< Clock, Duration > const& timeout_time) { return std::chrono::steady_clock::now() + ( timeout_time - Clock::now() ); } @@ -37,4 +39,4 @@ std::chrono::steady_clock::time_point convert_tp( std::chrono::time_point< Clock # include BOOST_ABI_SUFFIX #endif -#endif // BOOST_FIBERS_DETAIL_CONVERT_H +#endif // BOOST_FIBERS_DETAIL_CLOCK_CAST_H diff --git a/include/boost/fiber/detail/queues.hpp b/include/boost/fiber/detail/queues.hpp index e470087f..558de57c 100644 --- a/include/boost/fiber/detail/queues.hpp +++ b/include/boost/fiber/detail/queues.hpp @@ -49,7 +49,7 @@ struct sleep_tag; typedef intrusive::list_member_hook< intrusive::tag< sleep_tag >, intrusive::link_mode< - intrusive::safe_link + intrusive::auto_unlink > > sleep_hook; template< typename T > diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index bd69968c..531941ee 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -38,9 +39,10 @@ void yield() { } template< typename Clock, typename Duration > -void sleep_until( std::chrono::time_point< Clock, Duration > const& sleep_time) { +void sleep_until( std::chrono::time_point< Clock, Duration > const& sleep_time_) { + std::chrono::steady_clock::time_point sleep_time( + boost::fibers::detail::clock_cast( sleep_time_) ); fibers::context::active()->do_wait_until( sleep_time); - // check if fiber was interrupted interruption_point(); } @@ -79,32 +81,17 @@ void migrate( fiber const& f) { context::active()->do_spawn( f); } +inline +std::size_t ready_fibers() { + return context::active()->do_ready_fibers(); +} + template< typename SchedAlgo, typename ... Args > void use_scheduling_algorithm( Args && ... args) { context::active()->do_set_sched_algo( std::make_unique< SchedAlgo >( std::forward< Args >( args) ... ) ); } -template< typename Rep, typename Period > -void wait_interval( std::chrono::duration< Rep, Period > const& wait_interval) noexcept { - context::active()->do_wait_interval( wait_interval); -} - -inline -std::chrono::steady_clock::duration wait_interval() noexcept { - return context::active()->do_wait_interval(); -} - -template< typename Rep, typename Period > -std::chrono::duration< Rep, Period > wait_interval() noexcept { - return context::active()->do_wait_interval< Rep, Period >(); -} - -inline -std::size_t ready_fibers() { - return context::active()->do_ready_fibers(); -} - }} #ifdef BOOST_HAS_ABI_HEADERS diff --git a/include/boost/fiber/recursive_timed_mutex.hpp b/include/boost/fiber/recursive_timed_mutex.hpp index 96f01891..71217476 100644 --- a/include/boost/fiber/recursive_timed_mutex.hpp +++ b/include/boost/fiber/recursive_timed_mutex.hpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include @@ -61,7 +61,7 @@ public: template< typename Clock, typename Duration > bool try_lock_until( std::chrono::time_point< Clock, Duration > const& timeout_time_) { std::chrono::steady_clock::time_point timeout_time( - detail::convert_tp( timeout_time_) ); + detail::clock_cast( timeout_time_) ); return try_lock_until_( timeout_time); } diff --git a/include/boost/fiber/scheduler.hpp b/include/boost/fiber/scheduler.hpp index ca1a0914..b999b67f 100644 --- a/include/boost/fiber/scheduler.hpp +++ b/include/boost/fiber/scheduler.hpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include @@ -57,29 +57,18 @@ public: void run( context *); - void wait( context *, detail::spinlock_lock &); - bool wait_until( context *, std::chrono::steady_clock::time_point const&); void yield( context *); - void join( context *,context *); - void signal( context *); + void remote_signal( context *); + size_t ready_fibers() const noexcept; void set_sched_algo( std::unique_ptr< sched_algorithm >); - - void wait_interval( std::chrono::steady_clock::duration const&) noexcept; - - template< typename Rep, typename Period > - void wait_interval( std::chrono::duration< Rep, Period > const& wait_interval) noexcept { - wait_interval( wait_interval); - } - - std::chrono::steady_clock::duration wait_interval() noexcept; }; }} diff --git a/include/boost/fiber/timed_mutex.hpp b/include/boost/fiber/timed_mutex.hpp index 026fcacd..67752814 100644 --- a/include/boost/fiber/timed_mutex.hpp +++ b/include/boost/fiber/timed_mutex.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include @@ -57,7 +57,7 @@ public: template< typename Clock, typename Duration > bool try_lock_until( std::chrono::time_point< Clock, Duration > const& timeout_time_) { std::chrono::steady_clock::time_point timeout_time( - detail::convert_tp( timeout_time_) ); + detail::clock_cast( timeout_time_) ); return try_lock_until_( timeout_time); } diff --git a/src/context.cpp b/src/context.cpp index fb41cefa..b954209d 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -76,6 +76,7 @@ context::join( context * f) { if ( is_terminated() ) { return false; } + f->set_waiting(); wait_queue_.push_back( f); return true; } @@ -143,14 +144,6 @@ context::set_properties( fiber_properties * props) { properties_ = props; } -bool -context::do_wait_until_( std::chrono::steady_clock::time_point const& time_point) { - BOOST_ASSERT( nullptr != scheduler_); - BOOST_ASSERT( this == active_); - - return scheduler_->wait_until( this, time_point); -} - void context::do_spawn( fiber const& f) { BOOST_ASSERT( nullptr != scheduler_); @@ -167,6 +160,14 @@ context::do_schedule() { scheduler_->run( this); } +bool +context::do_wait_until( std::chrono::steady_clock::time_point const& time_point) { + BOOST_ASSERT( nullptr != scheduler_); + BOOST_ASSERT( this == active_); + + return scheduler_->wait_until( this, time_point); +} + void context::do_yield() { BOOST_ASSERT( nullptr != scheduler_); @@ -198,7 +199,7 @@ context::do_signal( context * f) { scheduler_->signal( f); } else { // scheduler in another thread - f->scheduler_->signal( f); + f->scheduler_->remote_signal( f); } } @@ -218,14 +219,6 @@ context::do_set_sched_algo( std::unique_ptr< sched_algorithm > algo) { scheduler_->set_sched_algo( std::move( algo) ); } -std::chrono::steady_clock::duration -context::do_wait_interval() noexcept { - BOOST_ASSERT( nullptr != scheduler_); - BOOST_ASSERT( this == active_); - - return scheduler_->wait_interval(); -} - }} #ifdef BOOST_HAS_ABI_HEADERS diff --git a/src/fiber.cpp b/src/fiber.cpp index 30e0b22b..be45f8a3 100644 --- a/src/fiber.cpp +++ b/src/fiber.cpp @@ -73,6 +73,7 @@ fiber::interrupt() noexcept { BOOST_ASSERT( impl_); impl_->request_interruption( true); + context::active()->do_signal( impl_.get() ); } }} diff --git a/src/mutex.cpp b/src/mutex.cpp index b2f694a0..400adc60 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -55,14 +55,22 @@ mutex::lock() { return; } - // store this fiber in order to be notified later - BOOST_ASSERT( ! f->wait_is_linked() ); - f->set_waiting(); - wait_queue_.push_back( * f); - lk.unlock(); + try { + // store this fiber in order to be notified later + BOOST_ASSERT( ! f->wait_is_linked() ); + f->set_waiting(); + wait_queue_.push_back( * f); + lk.unlock(); - // suspend this fiber - f->do_schedule(); + // check if fiber was interrupted + this_fiber::interruption_point(); + // suspend this fiber + f->do_schedule(); + } catch (...) { + detail::spinlock_lock lk( splk_); + f->wait_unlink(); + throw; + } } } diff --git a/src/recursive_mutex.cpp b/src/recursive_mutex.cpp index 1f54477c..a5541f36 100644 --- a/src/recursive_mutex.cpp +++ b/src/recursive_mutex.cpp @@ -61,14 +61,22 @@ recursive_mutex::lock() { return; } - // store this fiber in order to be notified later - BOOST_ASSERT( ! f->wait_is_linked() ); - f->set_waiting(); - wait_queue_.push_back( * f); - lk.unlock(); + try { + // store this fiber in order to be notified later + BOOST_ASSERT( ! f->wait_is_linked() ); + f->set_waiting(); + wait_queue_.push_back( * f); + lk.unlock(); - // suspend this fiber - f->do_schedule(); + // check if fiber was interrupted + this_fiber::interruption_point(); + // suspend this fiber + f->do_schedule(); + } catch (...) { + detail::spinlock_lock lk( splk_); + f->wait_unlink(); + throw; + } } } diff --git a/src/recursive_timed_mutex.cpp b/src/recursive_timed_mutex.cpp index bf7e54cb..b4a639b2 100644 --- a/src/recursive_timed_mutex.cpp +++ b/src/recursive_timed_mutex.cpp @@ -61,14 +61,22 @@ recursive_timed_mutex::lock() { return; } - // store this fiber in order to be notified later - BOOST_ASSERT( ! f->wait_is_linked() ); - f->set_waiting(); - wait_queue_.push_back( * f); - lk.unlock(); + try { + // store this fiber in order to be notified later + BOOST_ASSERT( ! f->wait_is_linked() ); + f->set_waiting(); + wait_queue_.push_back( * f); + lk.unlock(); - // suspend this fiber - f->do_schedule(); + // check if fiber was interrupted + this_fiber::interruption_point(); + // suspend this fiber + f->do_schedule(); + } catch (...) { + detail::spinlock_lock lk( splk_); + f->wait_unlink(); + throw; + } } } @@ -102,18 +110,26 @@ recursive_timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point co return true; } - // store this fiber in order to be notified later - BOOST_ASSERT( ! f->wait_is_linked() ); - f->set_waiting(); - wait_queue_.push_back( * f); - lk.unlock(); - - // suspend this fiber until notified or timed-out - if ( ! f->do_wait_until( timeout_time) ) { - lk.lock(); - f->wait_unlink(); + try { + // store this fiber in order to be notified later + BOOST_ASSERT( ! f->wait_is_linked() ); + f->set_waiting(); + wait_queue_.push_back( * f); lk.unlock(); - return false; + + // check if fiber was interrupted + this_fiber::interruption_point(); + // suspend this fiber until notified or timed-out + if ( ! f->do_wait_until( timeout_time) ) { + lk.lock(); + f->wait_unlink(); + lk.unlock(); + return false; + } + } catch (...) { + detail::spinlock_lock lk( splk_); + f->wait_unlink(); + throw; } } } diff --git a/src/round_robin.cpp b/src/round_robin.cpp index f12ab429..aff5bfdc 100644 --- a/src/round_robin.cpp +++ b/src/round_robin.cpp @@ -30,6 +30,7 @@ round_robin::pick_next() { victim = & runnable_queue_.front(); runnable_queue_.pop_front(); BOOST_ASSERT( nullptr != victim); + BOOST_ASSERT( ! victim->runnable_is_linked() ); } return victim; } diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 3007b9ad..be0c0cd0 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -66,7 +66,6 @@ scheduler::~scheduler() noexcept { BOOST_ASSERT( ! f->runnable_is_linked() ); BOOST_ASSERT( ! f->ready_is_linked() ); BOOST_ASSERT( ! f->sleep_is_linked() ); - //BOOST_ASSERT( ! f->wait_is_linked() ); sched_algo_->awakened( f); } else { ++i; @@ -78,7 +77,6 @@ scheduler::~scheduler() noexcept { BOOST_ASSERT( ! f->runnable_is_linked() ); BOOST_ASSERT( ! f->ready_is_linked() ); BOOST_ASSERT( ! f->sleep_is_linked() ); - //BOOST_ASSERT( ! f->wait_is_linked() ); BOOST_ASSERT_MSG( f->is_ready(), "fiber with invalid state in ready-queue"); // set scheduler f->set_scheduler( this); @@ -151,6 +149,7 @@ scheduler::spawn( context * f) { BOOST_ASSERT( ! f->runnable_is_linked() ); BOOST_ASSERT( ! f->ready_is_linked() ); BOOST_ASSERT( ! f->sleep_is_linked() ); + f->set_scheduler( this); sched_algo_->awakened( f); } @@ -169,14 +168,17 @@ scheduler::run( context * af) { i = ready_queue_.erase( i); BOOST_ASSERT( ! f->runnable_is_linked() ); BOOST_ASSERT( ! f->ready_is_linked() ); - BOOST_ASSERT( ! f->sleep_is_linked() ); - //BOOST_ASSERT( ! f->wait_is_linked() ); + // timed_mutex::try_lock_until() -> add f to waiting-queue + // -> add f to sleeping-queue + if ( f->sleep_is_linked() ) { + f->sleep_unlink(); + } sched_algo_->awakened( f); } } { // move all fibers which are ready (state_ready) - // from waiting-queue to the ready-queue + // from waiting-queue to the runnable-queue std::chrono::steady_clock::time_point now( std::chrono::steady_clock::now() ); sleep_queue_t::iterator e = sleep_queue_.end(); @@ -197,7 +199,6 @@ scheduler::run( context * af) { BOOST_ASSERT( ! f->runnable_is_linked() ); BOOST_ASSERT( ! f->ready_is_linked() ); BOOST_ASSERT( ! f->sleep_is_linked() ); - //BOOST_ASSERT( ! f->wait_is_linked() ); sched_algo_->awakened( f); } else { ++i; @@ -210,7 +211,6 @@ scheduler::run( context * af) { BOOST_ASSERT( ! f->runnable_is_linked() ); BOOST_ASSERT( ! f->ready_is_linked() ); BOOST_ASSERT( ! f->sleep_is_linked() ); - //BOOST_ASSERT( ! f->wait_is_linked() ); BOOST_ASSERT_MSG( f->is_ready(), "fiber with invalid state in ready-queue"); // resume fiber f resume_( af, f); @@ -238,7 +238,11 @@ scheduler::wait_until( context * af, std::chrono::steady_clock::time_point const& timeout_time) { BOOST_ASSERT( nullptr != af); BOOST_ASSERT( context::active() == af); + // from this_fiber::sleep() -> running + // from timed_mutex::lock_until() -> waiting BOOST_ASSERT( af->is_running() || af->is_waiting() ); + // set to state_waiting + af->set_waiting(); // push active-fiber to waiting-queue af->time_point( timeout_time); BOOST_ASSERT( ! af->sleep_is_linked() ); @@ -269,57 +273,31 @@ scheduler::yield( context * af) { // yield() should not be an interruption point } -void -scheduler::join( context * af, context * f) { - BOOST_ASSERT( nullptr != af); - BOOST_ASSERT( context::active() == af); - BOOST_ASSERT( af->is_running() ); - BOOST_ASSERT( nullptr != f); - BOOST_ASSERT( f != af); - // set active-fiber to state_waiting - af->set_waiting(); - // push active-fiber to waiting-queue - BOOST_ASSERT( ! af->sleep_is_linked() ); - sleep_queue_.push_back( * af); - // add active-fiber to joinig-list of f - if ( ! f->join( af) ) { - // f must be already terminated therefore we set - // active-fiber to state_ready - // FIXME: better state_running and no suspend - af->set_ready(); - } - // switch to another fiber - run( af); - // fiber has been resumed - // check if fiber was interrupted - this_fiber::interruption_point(); - // check that fiber f has terminated - BOOST_ASSERT( f->is_terminated() ); -} - void scheduler::signal( context * f) { BOOST_ASSERT( nullptr != f); BOOST_ASSERT( ! f->is_terminated() ); - // set fiber to state_ready - f->set_ready(); - // put reafy fiber ot read-queue - ready_queue_.push_back( * f); + + // a fiber MUST NOT be multiple times + // in runnable- or ready-queue + if ( ! f->ready_is_linked() && + ! f->runnable_is_linked() ) { + // set fiber to state_ready + f->set_ready(); + // put reafy fiber ot read-queue + ready_queue_.push_back( * f); + } } void -scheduler::set_sched_algo( std::unique_ptr< sched_algorithm > algo) { - sched_algo_ = std::move( algo); -} +scheduler::remote_signal( context * f) { + BOOST_ASSERT( nullptr != f); + BOOST_ASSERT( ! f->is_terminated() ); -void -scheduler::wait_interval( std::chrono::steady_clock::duration const& wait_interval) noexcept { - wait_interval_ = wait_interval; -} - -std::chrono::steady_clock::duration -scheduler::wait_interval() noexcept { - return wait_interval_; + BOOST_ASSERT_MSG( false, "not implemented"); + // FIXME: add context f to a thread-safe queue + // check that context f is not yet in + // local runnable- or ready-queue } std::size_t @@ -327,6 +305,11 @@ scheduler::ready_fibers() const noexcept { return sched_algo_->ready_fibers(); } +void +scheduler::set_sched_algo( std::unique_ptr< sched_algorithm > algo) { + sched_algo_ = std::move( algo); +} + }} #ifdef BOOST_HAS_ABI_HEADERS diff --git a/src/timed_mutex.cpp b/src/timed_mutex.cpp index 745a989f..40e88094 100644 --- a/src/timed_mutex.cpp +++ b/src/timed_mutex.cpp @@ -55,14 +55,22 @@ timed_mutex::lock() { return; } - // store this fiber in order to be notified later - BOOST_ASSERT( ! f->wait_is_linked() ); - f->set_waiting(); - wait_queue_.push_back( * f); - lk.unlock(); + try { + // store this fiber in order to be notified later + BOOST_ASSERT( ! f->wait_is_linked() ); + f->set_waiting(); + wait_queue_.push_back( * f); + lk.unlock(); - // suspend this fiber - f->do_schedule(); + // check if fiber was interrupted + this_fiber::interruption_point(); + // suspend this fiber + f->do_schedule(); + } catch (...) { + detail::spinlock_lock lk( splk_); + f->wait_unlink(); + throw; + } } } @@ -96,18 +104,26 @@ timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point const& timeo return true; } - // store this fiber in order to be notified later - BOOST_ASSERT( ! f->wait_is_linked() ); - f->set_waiting(); - wait_queue_.push_back( * f); - lk.unlock(); - - // suspend this fiber until notified or timed-out - if ( ! context::active()->do_wait_until( timeout_time) ) { - lk.lock(); - f->wait_unlink(); + try { + // store this fiber in order to be notified later + BOOST_ASSERT( ! f->wait_is_linked() ); + f->set_waiting(); + wait_queue_.push_back( * f); lk.unlock(); - return false; + + // check if fiber was interrupted + this_fiber::interruption_point(); + // suspend this fiber until notified or timed-out + if ( ! context::active()->do_wait_until( timeout_time) ) { + lk.lock(); + f->wait_unlink(); + lk.unlock(); + return false; + } + } catch (...) { + detail::spinlock_lock lk( splk_); + f->wait_unlink(); + throw; } } } diff --git a/test/test_bounded_channel.cpp b/test/test_bounded_channel.cpp index 082423b0..844e0691 100644 --- a/test/test_bounded_channel.cpp +++ b/test/test_bounded_channel.cpp @@ -434,12 +434,12 @@ void test_wm_1() BOOST_CHECK_EQUAL( id1, ids[2]); // f1 pushes 3 BOOST_CHECK_EQUAL( id1, ids[3]); // f1 blocks in push( 4) (channel is full) BOOST_CHECK_EQUAL( id2, ids[4]); // f2 resumes and pops 1, f1 gets ready to push 4, f2 yields - BOOST_CHECK_EQUAL( id2, ids[5]); // f2 resumes and pops 2 - BOOST_CHECK_EQUAL( id2, ids[6]); // f2 pops 4 + BOOST_CHECK_EQUAL( id1, ids[5]); // f1 resumes and pushes 4, blocks in push( 5) (channel full) + BOOST_CHECK_EQUAL( id2, ids[6]); // f2 resumes and pops 2 BOOST_CHECK_EQUAL( id2, ids[7]); // f2 pops 3 - BOOST_CHECK_EQUAL( id1, ids[8]); // f1 resumes and pushes 4, blocks in push( 5) (channel full) - BOOST_CHECK_EQUAL( id1, ids[9]); // f1 resumes and pushes 4, completes - BOOST_CHECK_EQUAL( id2, ids[10]); // f2 blocks in pop() (channel is empty) + BOOST_CHECK_EQUAL( id2, ids[8]); // f2 pops 4 + BOOST_CHECK_EQUAL( id2, ids[9]); // f2 blocks in pop() (channel is empty) + BOOST_CHECK_EQUAL( id1, ids[10]); // f1 resumes and pushes 4, completes BOOST_CHECK_EQUAL( id2, ids[11]); // f2 resumes and pops 5, completes } @@ -501,8 +501,8 @@ void test_wm_2() BOOST_CHECK_EQUAL( id1, ids[2]); // f1 pushes 3 BOOST_CHECK_EQUAL( id1, ids[3]); // f1 blocks in push( 4) (channel is full) BOOST_CHECK_EQUAL( id2, ids[4]); // f2 resumes and pops 1, f1 gets ready to push 4, f2 yields - BOOST_CHECK_EQUAL( id2, ids[5]); // f2 resumes and pops 2, f1 gets ready tp push 5, f2 yields - BOOST_CHECK_EQUAL( id1, ids[6]); // f1 resumes and pushes 4, blocks in push( 5) (channel full) + BOOST_CHECK_EQUAL( id1, ids[5]); // f1 resumes and pushes 4, blocks in push( 5) (channel full) + BOOST_CHECK_EQUAL( id2, ids[6]); // f2 resumes and pops 2, f1 gets ready tp push 5, f2 yields BOOST_CHECK_EQUAL( id1, ids[7]); // f1 resumes and pushes 5, completes BOOST_CHECK_EQUAL( id2, ids[8]); // f2 resumes and pops 3 BOOST_CHECK_EQUAL( id2, ids[9]); // f2 pops 4 @@ -570,10 +570,10 @@ void test_wm_3() BOOST_CHECK_EQUAL( id1, ids[3]); // f1 blocks in push( 4) (channel is full) BOOST_CHECK_EQUAL( id2, ids[4]); // f2 resumes and pops 1, f1 gets NOT ready to push 4, f2 yields BOOST_CHECK_EQUAL( id2, ids[5]); // f2 pops 2, f1 gets ready to push 4 (lwm == size == 1), f2 yields - BOOST_CHECK_EQUAL( id2, ids[6]); // f2 pops 4 - BOOST_CHECK_EQUAL( id2, ids[7]); // f2 resumes and pops 3 - BOOST_CHECK_EQUAL( id1, ids[8]); // f1 resumes and pushes 4 + 5 - BOOST_CHECK_EQUAL( id1, ids[9]); // f1 completes + BOOST_CHECK_EQUAL( id1, ids[6]); // f1 resumes and pushes 4 + 5 + BOOST_CHECK_EQUAL( id1, ids[7]); // f1 completes + BOOST_CHECK_EQUAL( id2, ids[8]); // f2 resumes and pops 3 + BOOST_CHECK_EQUAL( id2, ids[9]); // f2 pops 4 BOOST_CHECK_EQUAL( id2, ids[10]); // f2 pops 5 BOOST_CHECK_EQUAL( id2, ids[11]); // f2 completes } @@ -634,8 +634,8 @@ void test_wm_4() BOOST_CHECK_EQUAL( id1, ids[3]); // f1 blocks in push( 4) ( channel full) BOOST_CHECK_EQUAL( id2, ids[4]); // f2 resumes and pops 1, f1 gets NOT ready to push 4, f2 yields BOOST_CHECK_EQUAL( id2, ids[5]); // f2 pops 2, f1 gets ready to push 4 (lwm == size == 1), f2 yields - BOOST_CHECK_EQUAL( id2, ids[6]); // f2 resumes and pops 3 - BOOST_CHECK_EQUAL( id1, ids[7]); // f1 resumes and pushes 4, completes + BOOST_CHECK_EQUAL( id1, ids[6]); // f1 resumes and pushes 4, completes + BOOST_CHECK_EQUAL( id2, ids[7]); // f2 resumes and pops 3 BOOST_CHECK_EQUAL( id2, ids[8]); // f2 pops 4 BOOST_CHECK_EQUAL( id2, ids[9]); // f2 completes }