4#if qStroika_Foundation_Common_Platform_Windows
6#elif qStroika_Foundation_Common_Platform_POSIX
26 inline void Sleep (Time::Duration seconds2Wait, Time::DurationSeconds* remainingInSleep)
28 Require (seconds2Wait >= 0.0s);
32#if qStroika_Foundation_Common_Platform_POSIX
33 if constexpr (qStroika_Foundation_Common_Platform_POSIX) {
34 constexpr long kNanoSecondsPerSecond = 1000L * 1000L * 1000L;
36 ts.tv_sec = seconds2Wait.As<time_t> ();
37 ts.tv_nsec =
static_cast<long> (kNanoSecondsPerSecond * (seconds2Wait.As<
double> () - ts.tv_sec));
38 Assert (0 <= ts.tv_sec);
39 Assert (0 <= ts.tv_nsec and ts.tv_nsec < kNanoSecondsPerSecond);
41 int nanoSleepResult = ::nanosleep (&ts, &nextTS);
44#if _POSIX_C_SOURCE >= 200809L
45 if (nanoSleepResult < 0 and errno == EINVAL) {
46 if ((errno = ::clock_nanosleep (CLOCK_MONOTONIC, 0, &ts, &nextTS)) == 0) {
51 if (nanoSleepResult == 0) {
52 *remainingInSleep = 0s;
55 Assert (errno == EINTR);
58 WeakAssert (0 <= nextTS.tv_nsec and nextTS.tv_nsec < kNanoSecondsPerSecond);
61 Time::DurationSeconds{nextTS.tv_sec +
static_cast<Time::DurationSeconds::rep
> (nextTS.tv_nsec) / kNanoSecondsPerSecond};
64#elif qStroika_Foundation_Common_Platform_Windows
65 if constexpr (qStroika_Foundation_Common_Platform_Windows) {
66 Time::TimePointSeconds tc = Time::GetTickCount ();
67 if (::SleepEx (
static_cast<int> (seconds2Wait.count () * 1000),
true) == 0) {
68 *remainingInSleep = 0s;
71 Time::DurationSeconds remaining = (tc + seconds2Wait) - Time::GetTickCount ();
75 *remainingInSleep = remaining;
81 Ensure (*remainingInSleep <= seconds2Wait);
82 Ensure (*remainingInSleep >= 0s);
94 if (waitMoreSeconds <= 0s) {
98 Sleep (waitMoreSeconds);
#define AssertNotImplemented()
#define RequireNotNull(p)
#define WeakAssert(c)
A WeakAssert() is for things that aren't guaranteed to be true, but are overwhelmingly likely to be t...
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
void CheckForInterruption()
void Sleep(Time::Duration seconds2Wait)
void SleepUntil(Time::TimePointSeconds untilTickCount)