@@ -29,12 +29,6 @@ _STL_DISABLE_CLANG_WARNINGS
29
29
30
30
_STD_BEGIN
31
31
32
- template <class _Rep, class _Period>
33
- _NODISCARD unsigned long long _Semaphore_deadline(const chrono::duration<_Rep, _Period>& _Rel_time) {
34
- return __std_atomic_wait_get_deadline(
35
- chrono::duration_cast<chrono::duration<unsigned long long, milli>>(_Rel_time).count());
36
- }
37
-
38
32
template <class _Clock, class _Duration>
39
33
_NODISCARD unsigned long _Semaphore_remaining_timeout(const chrono::time_point<_Clock, _Duration>& _Abs_time) {
40
34
const auto _Now = _Clock::now();
@@ -145,11 +139,11 @@ public:
145
139
146
140
template <class _Rep, class _Period>
147
141
_NODISCARD_TRY_CHANGE_STATE bool try_acquire_for(const chrono::duration<_Rep, _Period>& _Rel_time) {
148
- auto _Deadline = _Semaphore_deadline(_Rel_time) ;
142
+ auto _Deadline = _STD chrono::steady_clock::now() + _Rel_time ;
149
143
ptrdiff_t _Current = _Counter.load(memory_order_relaxed);
150
144
for (;;) {
151
145
while (_Current == 0) {
152
- const auto _Remaining_timeout = __std_atomic_wait_get_remaining_timeout (_Deadline);
146
+ const auto _Remaining_timeout = _Semaphore_remaining_timeout (_Deadline);
153
147
if (_Remaining_timeout == 0) {
154
148
return false;
155
149
}
@@ -257,7 +251,7 @@ public:
257
251
258
252
template <class _Rep, class _Period>
259
253
_NODISCARD_TRY_CHANGE_STATE bool try_acquire_for(const chrono::duration<_Rep, _Period>& _Rel_time) {
260
- auto _Deadline = _Semaphore_deadline(_Rel_time) ;
254
+ auto _Deadline = _STD chrono::steady_clock::now() + _Rel_time ;
261
255
for (;;) {
262
256
// "happens after release" ordering is provided by this exchange, so loads and waits can be relaxed
263
257
// TRANSITION, GH-1133: should be memory_order_acquire
@@ -267,7 +261,7 @@ public:
267
261
}
268
262
_STL_VERIFY(_Prev == 0, "Invariant: semaphore counter is non-negative and doesn't exceed max(), "
269
263
"possibly caused by memory corruption");
270
- const auto _Remaining_timeout = __std_atomic_wait_get_remaining_timeout (_Deadline);
264
+ const auto _Remaining_timeout = _Semaphore_remaining_timeout (_Deadline);
271
265
if (_Remaining_timeout == 0) {
272
266
return false;
273
267
}
0 commit comments