Skip to content

Commit

Permalink
fix suspend timeout for Awaiter<StdContext> (#490)
Browse files Browse the repository at this point in the history
Signed-off-by: liulanzheng <lanzheng.liulz@alibaba-inc.com>
  • Loading branch information
liulanzheng committed May 23, 2024
1 parent 27550d5 commit 38c06d9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions thread/awaiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ struct Awaiter<StdContext> {
std::promise<void> p;
void resume() { return p.set_value(); }
int suspend(Timeout timeout = {}) {
auto ret = p.get_future().wait_for(timeout.std_duration());
if (ret == std::future_status::timeout) {
errno = ETIMEDOUT;
return -1;
auto duration = timeout.std_duration();
if (duration == std::chrono::microseconds().max()) {
p.get_future().wait();
} else {
auto ret = p.get_future().wait_for(duration);
if (ret == std::future_status::timeout) {
errno = ETIMEDOUT;
return -1;
}
}
return 0;
}
Expand Down

0 comments on commit 38c06d9

Please sign in to comment.