diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 7dc3b843..b11fd865 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -29,7 +29,7 @@ project boost/fiber lib boost_fiber : algorithm.cpp barrier.cpp - condition.cpp + condition_variable.cpp context.cpp detail/spinlock.cpp fiber.cpp diff --git a/include/boost/fiber/all.hpp b/include/boost/fiber/all.hpp index cc1a3cee..59ce0180 100644 --- a/include/boost/fiber/all.hpp +++ b/include/boost/fiber/all.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/boost/fiber/barrier.hpp b/include/boost/fiber/barrier.hpp index 0596c71f..debe7d72 100644 --- a/include/boost/fiber/barrier.hpp +++ b/include/boost/fiber/barrier.hpp @@ -11,7 +11,7 @@ #include -#include +#include #include #include @@ -24,11 +24,11 @@ namespace fibers { class BOOST_FIBERS_DECL barrier { private: - std::size_t initial_; - std::size_t current_; - bool cycle_{ true }; - mutex mtx_{}; - condition cond_{}; + std::size_t initial_; + std::size_t current_; + bool cycle_{ true }; + mutex mtx_{}; + condition_variable cond_{}; public: explicit barrier( std::size_t); diff --git a/include/boost/fiber/bounded_channel.hpp b/include/boost/fiber/bounded_channel.hpp index 6c5523dd..afdfa733 100644 --- a/include/boost/fiber/bounded_channel.hpp +++ b/include/boost/fiber/bounded_channel.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include @@ -88,8 +88,8 @@ private: ptr_t head_{}; ptr_t * tail_; mutable mutex mtx_{}; - condition not_empty_cond_{}; - condition not_full_cond_{}; + condition_variable not_empty_cond_{}; + condition_variable not_full_cond_{}; std::size_t hwm_; std::size_t lwm_; diff --git a/include/boost/fiber/condition.hpp b/include/boost/fiber/condition_variable.hpp similarity index 92% rename from include/boost/fiber/condition.hpp rename to include/boost/fiber/condition_variable.hpp index 7460b4a9..a797a139 100644 --- a/include/boost/fiber/condition.hpp +++ b/include/boost/fiber/condition_variable.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_CONDITION_H -#define BOOST_FIBERS_CONDITION_H +#ifndef BOOST_FIBERS_CONDITION_VARIABLE_H +#define BOOST_FIBERS_CONDITION_VARIABLE_H #include #include @@ -36,7 +36,7 @@ enum class cv_status { timeout }; -class BOOST_FIBERS_DECL condition { +class BOOST_FIBERS_DECL condition_variable { private: typedef context::wait_queue_t wait_queue_t; @@ -44,14 +44,14 @@ private: detail::spinlock wait_queue_splk_{}; public: - condition() = default; + condition_variable() = default; - ~condition() { + ~condition_variable() { BOOST_ASSERT( wait_queue_.empty() ); } - condition( condition const&) = delete; - condition & operator=( condition const&) = delete; + condition_variable( condition_variable const&) = delete; + condition_variable & operator=( condition_variable const&) = delete; void notify_one() noexcept; @@ -165,8 +165,7 @@ public: } }; -typedef condition condition_variable; -typedef condition condition_variable_any; +using condition_variable_any = condition_variable; }} @@ -174,4 +173,4 @@ typedef condition condition_variable_any; # include BOOST_ABI_SUFFIX #endif -#endif // BOOST_FIBERS_CONDITION_H +#endif // BOOST_FIBERS_CONDITION_VARIABLE_H diff --git a/include/boost/fiber/future/detail/shared_state.hpp b/include/boost/fiber/future/detail/shared_state.hpp index 298ee14c..c16b961d 100644 --- a/include/boost/fiber/future/detail/shared_state.hpp +++ b/include/boost/fiber/future/detail/shared_state.hpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -37,7 +37,7 @@ namespace detail { class shared_state_base { private: std::atomic< std::size_t > use_count_{ 0 }; - mutable condition waiters_{}; + mutable condition_variable waiters_{}; protected: mutable mutex mtx_{}; diff --git a/include/boost/fiber/mutex.hpp b/include/boost/fiber/mutex.hpp index 823882cf..a3f62dfc 100644 --- a/include/boost/fiber/mutex.hpp +++ b/include/boost/fiber/mutex.hpp @@ -22,11 +22,11 @@ namespace boost { namespace fibers { -class condition; +class condition_variable; class BOOST_FIBERS_DECL mutex { private: - friend class condition; + friend class condition_variable; typedef context::wait_queue_t wait_queue_t; diff --git a/include/boost/fiber/recursive_mutex.hpp b/include/boost/fiber/recursive_mutex.hpp index 7e19d58c..432143d1 100644 --- a/include/boost/fiber/recursive_mutex.hpp +++ b/include/boost/fiber/recursive_mutex.hpp @@ -26,11 +26,11 @@ namespace boost { namespace fibers { -class condition; +class condition_variable; class BOOST_FIBERS_DECL recursive_mutex { private: - friend class condition; + friend class condition_variable; typedef context::wait_queue_t wait_queue_t; diff --git a/include/boost/fiber/recursive_timed_mutex.hpp b/include/boost/fiber/recursive_timed_mutex.hpp index 30f2445a..8cf7f116 100644 --- a/include/boost/fiber/recursive_timed_mutex.hpp +++ b/include/boost/fiber/recursive_timed_mutex.hpp @@ -28,11 +28,11 @@ namespace boost { namespace fibers { -class condition; +class condition_variable; class BOOST_FIBERS_DECL recursive_timed_mutex { private: - friend class condition; + friend class condition_variable; typedef context::wait_queue_t wait_queue_t; diff --git a/include/boost/fiber/timed_mutex.hpp b/include/boost/fiber/timed_mutex.hpp index 371e06ad..0abe69f0 100644 --- a/include/boost/fiber/timed_mutex.hpp +++ b/include/boost/fiber/timed_mutex.hpp @@ -24,11 +24,11 @@ namespace boost { namespace fibers { -class condition; +class condition_variable; class BOOST_FIBERS_DECL timed_mutex { private: - friend class condition; + friend class condition_variable; typedef context::wait_queue_t wait_queue_t; diff --git a/include/boost/fiber/unbounded_channel.hpp b/include/boost/fiber/unbounded_channel.hpp index f80a70c5..cf52d273 100644 --- a/include/boost/fiber/unbounded_channel.hpp +++ b/include/boost/fiber/unbounded_channel.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include @@ -89,7 +89,7 @@ private: ptr_t head_{}; ptr_t * tail_; mutable mutex mtx_{}; - condition not_empty_cond_{}; + condition_variable not_empty_cond_{}; bool is_closed_() const noexcept { return queue_status::closed == state_; diff --git a/src/condition.cpp b/src/condition_variable.cpp similarity index 88% rename from src/condition.cpp rename to src/condition_variable.cpp index 105fee77..a397056f 100644 --- a/src/condition.cpp +++ b/src/condition_variable.cpp @@ -4,7 +4,7 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include "boost/fiber/condition.hpp" +#include "boost/fiber/condition_variable.hpp" #include "boost/fiber/context.hpp" @@ -16,7 +16,7 @@ namespace boost { namespace fibers { void -condition::notify_one() noexcept { +condition_variable::notify_one() noexcept { // get one context' from wait-queue detail::spinlock_lock lk( wait_queue_splk_); if ( wait_queue_.empty() ) { @@ -29,7 +29,7 @@ condition::notify_one() noexcept { } void -condition::notify_all() noexcept { +condition_variable::notify_all() noexcept { // get all context' from wait-queue detail::spinlock_lock lk( wait_queue_splk_); // notify all context' diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 2f1b3965..dae7523a 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -321,8 +321,8 @@ scheduler::wait_until( context * active_ctx, //BOOST_ASSERT( main_ctx_ == active_ctx || dispatcher_ctx_.get() == active_ctx || active_ctx->worker_is_linked() ); BOOST_ASSERT( ! active_ctx->is_terminated() ); // if the active-fiber running in this thread calls - // condition:wait() and code in another thread calls - // condition::notify_one(), it might happen that the + // condition_variable:wait() and code in another thread calls + // condition_variable::notify_one(), it might happen that the // other thread pushes the fiber to remote ready-queue first // the dispatcher-context migh have been moved the fiber from // the remote ready-queue to the local ready-queue @@ -351,8 +351,8 @@ scheduler::wait_until( context * active_ctx, //BOOST_ASSERT( main_ctx_ == active_ctx || dispatcher_ctx_.get() == active_ctx || active_ctx->worker_is_linked() ); BOOST_ASSERT( ! active_ctx->is_terminated() ); // if the active-fiber running in this thread calls - // condition:wait() and code in another thread calls - // condition::notify_one(), it might happen that the + // condition_variable:wait() and code in another thread calls + // condition_variable::notify_one(), it might happen that the // other thread pushes the fiber to remote ready-queue first // the dispatcher-context migh have been moved the fiber from // the remote ready-queue to the local ready-queue diff --git a/test/test_condition.cpp b/test/test_condition.cpp index c858d14f..5bcd110b 100644 --- a/test/test_condition.cpp +++ b/test/test_condition.cpp @@ -37,7 +37,7 @@ struct condition_test_data { condition_test_data() : notified(0), awoken(0) { } boost::fibers::mutex mutex; - boost::fibers::condition condition; + boost::fibers::condition_variable cond; int notified; int awoken; }; @@ -46,7 +46,7 @@ void condition_test_fiber(condition_test_data* data) { std::unique_lock lock(data->mutex); BOOST_CHECK(lock ? true : false); while (!(data->notified > 0)) - data->condition.wait(lock); + data->cond.wait(lock); BOOST_CHECK(lock ? true : false); data->awoken++; } @@ -63,17 +63,17 @@ private: }; -void notify_one_fn( boost::fibers::condition & cond) { +void notify_one_fn( boost::fibers::condition_variable & cond) { cond.notify_one(); } -void notify_all_fn( boost::fibers::condition & cond) { +void notify_all_fn( boost::fibers::condition_variable & cond) { cond.notify_all(); } void wait_fn( boost::fibers::mutex & mtx, - boost::fibers::condition & cond) { + boost::fibers::condition_variable & cond) { std::unique_lock< boost::fibers::mutex > lk( mtx); cond.wait( lk); ++value; @@ -101,7 +101,7 @@ void test_condition_wait_is_a_interruption_point() { void test_one_waiter_notify_one() { value = 0; boost::fibers::mutex mtx; - boost::fibers::condition cond; + boost::fibers::condition_variable cond; boost::fibers::fiber f1( wait_fn, @@ -124,7 +124,7 @@ void test_one_waiter_notify_one() { void test_two_waiter_notify_one() { value = 0; boost::fibers::mutex mtx; - boost::fibers::condition cond; + boost::fibers::condition_variable cond; boost::fibers::fiber f1( wait_fn, @@ -159,7 +159,7 @@ void test_two_waiter_notify_one() { void test_two_waiter_notify_all() { value = 0; boost::fibers::mutex mtx; - boost::fibers::condition cond; + boost::fibers::condition_variable cond; boost::fibers::fiber f1( wait_fn, @@ -487,7 +487,7 @@ void test_condition_wait_for_pred() { boost::unit_test::test_suite * init_unit_test_suite( int, char* []) { boost::unit_test::test_suite * test = - BOOST_TEST_SUITE("Boost.Fiber: condition test suite"); + BOOST_TEST_SUITE("Boost.Fiber: condition_variable test suite"); test->add( BOOST_TEST_CASE( & test_one_waiter_notify_one) ); test->add( BOOST_TEST_CASE( & test_two_waiter_notify_one) ); diff --git a/test/test_condition_mt.cpp b/test/test_condition_mt.cpp index 077761e3..34c3066b 100644 --- a/test/test_condition_mt.cpp +++ b/test/test_condition_mt.cpp @@ -31,7 +31,7 @@ boost::atomic< int > value; void wait_fn( boost::barrier & b, boost::fibers::mutex & mtx, - boost::fibers::condition & cond, + boost::fibers::condition_variable & cond, bool & flag) { b.wait(); std::unique_lock< boost::fibers::mutex > lk( mtx); @@ -41,7 +41,7 @@ void wait_fn( boost::barrier & b, void notify_one_fn( boost::barrier & b, boost::fibers::mutex & mtx, - boost::fibers::condition & cond, + boost::fibers::condition_variable & cond, bool & flag) { b.wait(); std::unique_lock< boost::fibers::mutex > lk( mtx); @@ -52,7 +52,7 @@ void notify_one_fn( boost::barrier & b, void notify_all_fn( boost::barrier & b, boost::fibers::mutex & mtx, - boost::fibers::condition & cond, + boost::fibers::condition_variable & cond, bool & flag) { b.wait(); std::unique_lock< boost::fibers::mutex > lk( mtx); @@ -63,7 +63,7 @@ void notify_all_fn( boost::barrier & b, void fn1( boost::barrier & b, boost::fibers::mutex & mtx, - boost::fibers::condition & cond, + boost::fibers::condition_variable & cond, bool & flag) { boost::fibers::fiber( wait_fn, @@ -75,7 +75,7 @@ void fn1( boost::barrier & b, void fn2( boost::barrier & b, boost::fibers::mutex & mtx, - boost::fibers::condition & cond, + boost::fibers::condition_variable & cond, bool & flag) { boost::fibers::fiber( notify_one_fn, @@ -87,7 +87,7 @@ void fn2( boost::barrier & b, void fn3( boost::barrier & b, boost::fibers::mutex & mtx, - boost::fibers::condition & cond, + boost::fibers::condition_variable & cond, bool & flag) { boost::fibers::fiber( notify_all_fn, @@ -104,7 +104,7 @@ void test_one_waiter_notify_one() { bool flag = false; value = 0; boost::fibers::mutex mtx; - boost::fibers::condition cond; + boost::fibers::condition_variable cond; BOOST_CHECK( 0 == value); @@ -125,7 +125,7 @@ void test_two_waiter_notify_all() { bool flag = false; value = 0; boost::fibers::mutex mtx; - boost::fibers::condition cond; + boost::fibers::condition_variable cond; BOOST_CHECK( 0 == value); @@ -147,7 +147,7 @@ void test_dummy() { boost::unit_test::test_suite * init_unit_test_suite( int, char* []) { boost::unit_test::test_suite * test = - BOOST_TEST_SUITE("Boost.Fiber: multithreaded condition test suite"); + BOOST_TEST_SUITE("Boost.Fiber: multithreaded condition_variable test suite"); #if ! defined(BOOST_FIBERS_NO_ATOMICS) test->add( BOOST_TEST_CASE( & test_one_waiter_notify_one) );