abseil / abseil/abseil-cpp

Add SleepUntil

オープン
#1,088 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
C++
スター
18.1k
フォーク
3.2k
平均マージ
20時間 36分
マージ済み PR(30日)
1

説明

Feature request: It would be great if Abseil exposed a `SleepUntil` function alongside `SleepFor`. A Linux implementation could be something like this:

```c++
// Copyright 2022 Benjamin Barenblat
// SPDX-License-Identifier: Apache-2.0

// SleepUntil()
//
// Sleeps until the current time is after the specified absolute time.
//
// Notes:
// * Signal interruptions will not reduce the sleep duration.
// * Returns immediately when given a time that has already passed.
void SleepUntil(absl::Time time) {
struct timespec wake_point = absl::ToTimespec(time);
while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &wake_point,
/*remain=*/nullptr) == EINTR) {
// Ignore signals and wait for the full interval to elapse.
}
}
```

This obviously won’t work on Windows, but I believe you can use [`SetWaitableTimer`](https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-setwaitabletimer) to achieve something similar. `clock_nanosleep` doesn’t exist on Apple OSes either; I’m not sure what the correct approach is there.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。