1 // Distributed under the Boost Software License, Version 1.0. (See 2 // accompanying file LICENSE_1_0.txt or copy at 3 // http://www.boost.org/LICENSE_1_0.txt) 4 // (C) Copyright 2013 Vicente J. Botet Escriba 5 6 #ifndef BOOST_THREAD_COUNTER_HPP 7 #define BOOST_THREAD_COUNTER_HPP 8 9 #include <boost/thread/detail/config.hpp> 10 #include <boost/thread/detail/delete.hpp> 11 12 //#include <boost/thread/mutex.hpp> 13 //#include <boost/thread/lock_types.hpp> 14 #include <boost/thread/condition_variable.hpp> 15 #include <boost/chrono/duration.hpp> 16 #include <boost/chrono/time_point.hpp> 17 #include <boost/assert.hpp> 18 19 #include <boost/config/abi_prefix.hpp> 20 21 namespace boost 22 { 23 namespace detail { 24 struct counter 25 { 26 condition_variable cond_; 27 std::size_t value_; 28 counterboost::detail::counter29 counter(std::size_t value) 30 : value_(value) 31 { 32 33 } operator =boost::detail::counter34 counter& operator=(counter const& rhs) 35 { 36 value_ = rhs.value_; 37 return *this; 38 } operator =boost::detail::counter39 counter& operator=(std::size_t value) 40 { 41 value_ = value; 42 return *this; 43 } 44 operator std::size_tboost::detail::counter45 operator std::size_t() const 46 { 47 return value_; 48 } operator std::size_t&boost::detail::counter49 operator std::size_t&() 50 { 51 return value_; 52 } 53 inc_and_notify_allboost::detail::counter54 void inc_and_notify_all() 55 { 56 ++value_; 57 cond_.notify_all(); 58 } 59 dec_and_notify_allboost::detail::counter60 void dec_and_notify_all() 61 { 62 --value_; 63 cond_.notify_all(); 64 } assign_and_notify_allboost::detail::counter65 void assign_and_notify_all(counter const& rhs) 66 { 67 value_ = rhs.value_; 68 cond_.notify_all(); 69 } assign_and_notify_allboost::detail::counter70 void assign_and_notify_all(std::size_t value) 71 { 72 value_ = value; 73 cond_.notify_all(); 74 } 75 }; 76 struct counter_is_not_zero 77 { counter_is_not_zeroboost::detail::counter_is_not_zero78 counter_is_not_zero(counter const& count) : count_(count) {} operator ()boost::detail::counter_is_not_zero79 bool operator()() const { return count_ != 0; } 80 counter const& count_; 81 }; 82 struct counter_is_zero 83 { counter_is_zeroboost::detail::counter_is_zero84 counter_is_zero(counter const& count) : count_(count) {} operator ()boost::detail::counter_is_zero85 bool operator()() const { return count_ == 0; } 86 counter const& count_; 87 }; 88 struct is_zero 89 { is_zeroboost::detail::is_zero90 is_zero(std::size_t& count) : count_(count) {} operator ()boost::detail::is_zero91 bool operator()() const { return count_ == 0; } 92 std::size_t& count_; 93 }; 94 struct not_equal 95 { not_equalboost::detail::not_equal96 not_equal(std::size_t& x, std::size_t& y) : x_(x), y_(y) {} operator ()boost::detail::not_equal97 bool operator()() const { return x_ != y_; } 98 std::size_t& x_; 99 std::size_t& y_; 100 }; 101 } 102 } // namespace boost 103 104 #include <boost/config/abi_suffix.hpp> 105 106 #endif 107