abseil / abseil/abseil-cpp

Add SleepUntil

Đang mở
#1,088 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
C++
Star
18.1k
Fork
3.2k
Merge trung bình
20 giờ 36 phút
Pull request đã merge (30 ngày)
1

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.