Skip to content

Commit bef8da2

Browse files
committed
Fix task_future::wait_until, remove manual check for predicate
1 parent 773ab11 commit bef8da2

2 files changed

Lines changed: 4 additions & 13 deletions

File tree

include/task.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ class task {
115115
* If the task is pending (`get_state() == task_state::pending`), blocks until task finishes or until the specified `timeout_time` has been reached.
116116
* Otherwise returns immediately without blocking.
117117
*
118-
* @returns `std::future_status::timeout` if the timeout has expired, otherwise `std::future_status::ready`.
118+
* @returns `false` if the timeout has expired, otherwise `true`.
119119
*/
120120
template<class Clock, class Duration>
121-
std::future_status wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time) const {
121+
bool wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time) const {
122122
return future->wait_until(timeout_time);
123123
}
124124

include/task_future.hpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,19 @@ class task_future_base {
5555

5656
void wait() {
5757
std::unique_lock<std::mutex> lock(mutex);
58-
if (state != task_state::pending) {
59-
return;
60-
}
6158
condition_variable.wait(lock, wait_predicate());
6259
}
6360

6461
template<class Rep, class Period>
6562
std::future_status wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
6663
std::unique_lock<std::mutex> lock(mutex);
67-
if (state != task_state::pending) {
68-
return std::future_status::ready;
69-
}
7064
return condition_variable.wait_for(lock, timeout_duration, wait_predicate());
7165
}
7266

7367
template<class Clock, class Duration>
74-
std::future_status wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time) {
68+
bool wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time) {
7569
std::unique_lock<std::mutex> lock(mutex);
76-
if (state != task_state::pending) {
77-
return std::future_status::ready;
78-
}
79-
return condition_variable.wait_for(lock, timeout_time, wait_predicate());
70+
return condition_variable.wait_until(lock, timeout_time, wait_predicate());
8071
}
8172

8273
protected:

0 commit comments

Comments
 (0)