Add SleepUntil
- 主要言語
- 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 はまだ評価されていません。