]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/include/boost/thread/detail/counter.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / thread / include / boost / thread / detail / counter.hpp
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
29 counter(std::size_t value)
30 : value_(value)
31 {
32
33 }
34 counter& operator=(counter const& rhs)
35 {
36 value_ = rhs.value_;
37 return *this;
38 }
39 counter& operator=(std::size_t value)
40 {
41 value_ = value;
42 return *this;
43 }
44
45 operator std::size_t() const
46 {
47 return value_;
48 }
49 operator std::size_t&()
50 {
51 return value_;
52 }
53
54 void inc_and_notify_all()
55 {
56 ++value_;
57 cond_.notify_all();
58 }
59
60 void dec_and_notify_all()
61 {
62 --value_;
63 cond_.notify_all();
64 }
65 void assign_and_notify_all(counter const& rhs)
66 {
67 value_ = rhs.value_;
68 cond_.notify_all();
69 }
70 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 {
78 counter_is_not_zero(counter const& count) : count_(count) {}
79 bool operator()() const { return count_ != 0; }
80 counter const& count_;
81 };
82 struct counter_is_zero
83 {
84 counter_is_zero(counter const& count) : count_(count) {}
85 bool operator()() const { return count_ == 0; }
86 counter const& count_;
87 };
88 struct is_zero
89 {
90 is_zero(std::size_t& count) : count_(count) {}
91 bool operator()() const { return count_ == 0; }
92 std::size_t& count_;
93 };
94 struct not_equal
95 {
96 not_equal(std::size_t& x, std::size_t& y) : x_(x), y_(y) {}
97 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