Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:45

0001 // Distributed under the Boost Software License, Version 1.0. (See
0002 // accompanying file LICENSE_1_0.txt or copy at
0003 // http://www.boost.org/LICENSE_1_0.txt)
0004 // (C) Copyright 2013 Vicente J. Botet Escriba
0005 
0006 #ifndef BOOST_THREAD_COUNTER_HPP
0007 #define BOOST_THREAD_COUNTER_HPP
0008 
0009 #include <boost/thread/detail/config.hpp>
0010 #include <boost/thread/detail/delete.hpp>
0011 
0012 //#include <boost/thread/mutex.hpp>
0013 //#include <boost/thread/lock_types.hpp>
0014 #include <boost/thread/condition_variable.hpp>
0015 #include <boost/chrono/duration.hpp>
0016 #include <boost/chrono/time_point.hpp>
0017 #include <boost/assert.hpp>
0018 
0019 #include <boost/config/abi_prefix.hpp>
0020 
0021 namespace boost
0022 {
0023   namespace detail {
0024     struct counter
0025     {
0026       condition_variable cond_;
0027       std::size_t value_;
0028 
0029       counter(std::size_t value)
0030       : value_(value)
0031       {
0032 
0033       }
0034       counter& operator=(counter const& rhs)
0035       {
0036         value_ = rhs.value_;
0037         return *this;
0038       }
0039       counter& operator=(std::size_t value)
0040       {
0041         value_ = value;
0042         return *this;
0043       }
0044 
0045       operator std::size_t() const
0046       {
0047         return value_;
0048       }
0049       operator std::size_t&()
0050       {
0051         return value_;
0052       }
0053 
0054       void inc_and_notify_all()
0055       {
0056         ++value_;
0057         cond_.notify_all();
0058       }
0059 
0060       void dec_and_notify_all()
0061       {
0062         --value_;
0063         cond_.notify_all();
0064       }
0065       void assign_and_notify_all(counter const& rhs)
0066       {
0067         value_ = rhs.value_;
0068         cond_.notify_all();
0069       }
0070       void assign_and_notify_all(std::size_t value)
0071       {
0072         value_ = value;
0073         cond_.notify_all();
0074       }
0075     };
0076     struct counter_is_not_zero
0077     {
0078       counter_is_not_zero(counter const& count) : count_(count) {}
0079       bool operator()() const { return count_ != 0; }
0080       counter const& count_;
0081     };
0082     struct counter_is_zero
0083     {
0084       counter_is_zero(counter const& count) : count_(count) {}
0085       bool operator()() const { return count_ == 0; }
0086       counter const& count_;
0087     };
0088     struct is_zero
0089     {
0090       is_zero(std::size_t& count) : count_(count) {}
0091       bool operator()() const { return count_ == 0; }
0092       std::size_t& count_;
0093     };
0094     struct not_equal
0095     {
0096       not_equal(std::size_t& x, std::size_t& y) : x_(x), y_(y) {}
0097       bool operator()() const { return x_ != y_; }
0098       std::size_t& x_;
0099       std::size_t& y_;
0100     };
0101   }
0102 } // namespace boost
0103 
0104 #include <boost/config/abi_suffix.hpp>
0105 
0106 #endif