@@ -39,60 +39,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
39
39
_LIBCPP_DECLARE_STRONG_ENUM (cv_status){no_timeout, timeout};
40
40
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG (cv_status)
41
41
42
- class _LIBCPP_EXPORTED_FROM_ABI condition_variable {
43
- __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER;
44
-
45
- public:
46
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR condition_variable () _NOEXCEPT = default ;
47
-
48
- # if _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
49
- ~condition_variable () = default ;
50
- # else
51
- ~condition_variable ();
52
- # endif
53
-
54
- condition_variable (const condition_variable&) = delete ;
55
- condition_variable& operator =(const condition_variable&) = delete ;
56
-
57
- void notify_one () _NOEXCEPT;
58
- void notify_all () _NOEXCEPT;
59
-
60
- void wait (unique_lock<mutex>& __lk) _NOEXCEPT;
61
- template <class _Predicate >
62
- _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS void wait (unique_lock<mutex>& __lk, _Predicate __pred);
63
-
64
- template <class _Clock , class _Duration >
65
- _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS cv_status
66
- wait_until (unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t );
67
-
68
- template <class _Clock , class _Duration , class _Predicate >
69
- _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
70
- wait_until (unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t , _Predicate __pred);
71
-
72
- template <class _Rep , class _Period >
73
- _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS cv_status
74
- wait_for (unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d);
75
-
76
- template <class _Rep , class _Period , class _Predicate >
77
- bool _LIBCPP_HIDE_FROM_ABI
78
- wait_for (unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred);
79
-
80
- typedef __libcpp_condvar_t * native_handle_type;
81
- _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle () { return &__cv_; }
82
-
83
- private:
84
- void
85
- __do_timed_wait (unique_lock<mutex>& __lk, chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT;
86
- # if _LIBCPP_HAS_COND_CLOCKWAIT
87
- _LIBCPP_HIDE_FROM_ABI void
88
- __do_timed_wait (unique_lock<mutex>& __lk, chrono::time_point<chrono::steady_clock, chrono::nanoseconds>) _NOEXCEPT;
89
- # endif
90
- template <class _Clock >
91
- _LIBCPP_HIDE_FROM_ABI void
92
- __do_timed_wait (unique_lock<mutex>& __lk, chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT;
93
- };
94
- #endif // _LIBCPP_HAS_THREADS
95
-
96
42
template <class _Rep, class _Period, __enable_if_t<is_floating_point<_Rep>::value, int> = 0>
97
43
inline _LIBCPP_HIDE_FROM_ABI chrono::nanoseconds __safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d) {
98
44
using namespace chrono ;
@@ -140,64 +86,106 @@ inline _LIBCPP_HIDE_FROM_ABI chrono::nanoseconds __safe_nanosecond_cast(chrono::
140
86
return nanoseconds (__result);
141
87
}
142
88
143
- #if _LIBCPP_HAS_THREADS
144
- template <class _Predicate >
145
- void condition_variable::wait (unique_lock<mutex>& __lk, _Predicate __pred) {
146
- while (!__pred ())
147
- wait (__lk);
148
- }
89
+ class _LIBCPP_EXPORTED_FROM_ABI condition_variable {
90
+ __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER;
149
91
150
- template <class _Clock , class _Duration >
151
- cv_status condition_variable::wait_until (unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t ) {
152
- using namespace chrono ;
153
- using __clock_tp_ns = time_point<_Clock, nanoseconds>;
92
+ public:
93
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR condition_variable () _NOEXCEPT = default;
154
94
155
- typename _Clock::time_point __now = _Clock::now ();
156
- if (__t <= __now)
157
- return cv_status::timeout;
95
+ # if _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
96
+ ~condition_variable () = default ;
97
+ # else
98
+ ~condition_variable ();
99
+ # endif
158
100
159
- __clock_tp_ns __t_ns = __clock_tp_ns (std::__safe_nanosecond_cast (__t .time_since_epoch ()));
101
+ condition_variable (const condition_variable&) = delete ;
102
+ condition_variable& operator =(const condition_variable&) = delete ;
160
103
161
- __do_timed_wait (__lk, __t_ns);
162
- return _Clock::now () < __t ? cv_status::no_timeout : cv_status::timeout;
163
- }
104
+ void notify_one () _NOEXCEPT;
105
+ void notify_all () _NOEXCEPT;
106
+
107
+ void wait (unique_lock<mutex>& __lk) _NOEXCEPT;
164
108
165
- template <class _Clock , class _Duration , class _Predicate >
166
- bool condition_variable::wait_until (
167
- unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t , _Predicate __pred) {
168
- while (!__pred ()) {
169
- if (wait_until (__lk, __t ) == cv_status::timeout)
170
- return __pred ();
109
+ template <class _Predicate >
110
+ _LIBCPP_HIDE_FROM_ABI void wait (unique_lock<mutex>& __lk, _Predicate __pred) {
111
+ while (!__pred ())
112
+ wait (__lk);
171
113
}
172
- return true ;
173
- }
174
114
175
- template <class _Rep , class _Period >
176
- cv_status condition_variable::wait_for (unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d) {
177
- using namespace chrono ;
178
- if (__d <= __d.zero ())
179
- return cv_status::timeout;
180
- using __ns_rep = nanoseconds::rep;
181
- steady_clock::time_point __c_now = steady_clock::now ();
115
+ template <class _Clock , class _Duration >
116
+ _LIBCPP_HIDE_FROM_ABI cv_status
117
+ wait_until (unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t ) {
118
+ using namespace chrono ;
119
+ using __clock_tp_ns = time_point<_Clock, nanoseconds>;
120
+
121
+ typename _Clock::time_point __now = _Clock::now ();
122
+ if (__t <= __now)
123
+ return cv_status::timeout;
124
+
125
+ __clock_tp_ns __t_ns = __clock_tp_ns (std::__safe_nanosecond_cast (__t .time_since_epoch ()));
126
+
127
+ __do_timed_wait (__lk, __t_ns);
128
+ return _Clock::now () < __t ? cv_status::no_timeout : cv_status::timeout;
129
+ }
130
+
131
+ template <class _Clock , class _Duration , class _Predicate >
132
+ _LIBCPP_HIDE_FROM_ABI bool
133
+ wait_until (unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t , _Predicate __pred) {
134
+ while (!__pred ()) {
135
+ if (wait_until (__lk, __t ) == cv_status::timeout)
136
+ return __pred ();
137
+ }
138
+ return true ;
139
+ }
140
+
141
+ template <class _Rep , class _Period >
142
+ _LIBCPP_HIDE_FROM_ABI cv_status wait_for (unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d) {
143
+ using namespace chrono ;
144
+ if (__d <= __d.zero ())
145
+ return cv_status::timeout;
146
+ using __ns_rep = nanoseconds::rep;
147
+ steady_clock::time_point __c_now = steady_clock::now ();
182
148
183
149
# if _LIBCPP_HAS_COND_CLOCKWAIT
184
- using __clock_tp_ns = time_point<steady_clock, nanoseconds>;
185
- __ns_rep __now_count_ns = std::__safe_nanosecond_cast (__c_now.time_since_epoch ()).count ();
150
+ using __clock_tp_ns = time_point<steady_clock, nanoseconds>;
151
+ __ns_rep __now_count_ns = std::__safe_nanosecond_cast (__c_now.time_since_epoch ()).count ();
186
152
# else
187
- using __clock_tp_ns = time_point<system_clock, nanoseconds>;
188
- __ns_rep __now_count_ns = std::__safe_nanosecond_cast (system_clock::now ().time_since_epoch ()).count ();
153
+ using __clock_tp_ns = time_point<system_clock, nanoseconds>;
154
+ __ns_rep __now_count_ns = std::__safe_nanosecond_cast (system_clock::now ().time_since_epoch ()).count ();
189
155
# endif
190
156
191
- __ns_rep __d_ns_count = std::__safe_nanosecond_cast (__d).count ();
157
+ __ns_rep __d_ns_count = std::__safe_nanosecond_cast (__d).count ();
192
158
193
- if (__now_count_ns > numeric_limits<__ns_rep>::max () - __d_ns_count) {
194
- __do_timed_wait (__lk, __clock_tp_ns::max ());
195
- } else {
196
- __do_timed_wait (__lk, __clock_tp_ns (nanoseconds (__now_count_ns + __d_ns_count)));
159
+ if (__now_count_ns > numeric_limits<__ns_rep>::max () - __d_ns_count) {
160
+ __do_timed_wait (__lk, __clock_tp_ns::max ());
161
+ } else {
162
+ __do_timed_wait (__lk, __clock_tp_ns (nanoseconds (__now_count_ns + __d_ns_count)));
163
+ }
164
+
165
+ return steady_clock::now () - __c_now < __d ? cv_status::no_timeout : cv_status::timeout;
197
166
}
198
167
199
- return steady_clock::now () - __c_now < __d ? cv_status::no_timeout : cv_status::timeout;
200
- }
168
+ template <class _Rep , class _Period , class _Predicate >
169
+ bool _LIBCPP_HIDE_FROM_ABI
170
+ wait_for (unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred);
171
+
172
+ typedef __libcpp_condvar_t * native_handle_type;
173
+ _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle () { return &__cv_; }
174
+
175
+ private:
176
+ void
177
+ __do_timed_wait (unique_lock<mutex>& __lk, chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT;
178
+ # if _LIBCPP_HAS_COND_CLOCKWAIT
179
+ _LIBCPP_HIDE_FROM_ABI void
180
+ __do_timed_wait (unique_lock<mutex>& __lk, chrono::time_point<chrono::steady_clock, chrono::nanoseconds>) _NOEXCEPT;
181
+ # endif
182
+ template <class _Clock >
183
+ _LIBCPP_HIDE_FROM_ABI void
184
+ __do_timed_wait (unique_lock<mutex>& __lk, chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT;
185
+ };
186
+ #endif // _LIBCPP_HAS_THREADS
187
+
188
+ #if _LIBCPP_HAS_THREADS
201
189
202
190
template <class _Rep , class _Period , class _Predicate >
203
191
inline bool
0 commit comments