4#if qStroika_Foundation_Common_Platform_Windows
6#elif qStroika_Foundation_Common_Platform_POSIX
26 inline void Sleep (Time::Duration seconds2Wait, Time::DurationSeconds* remainingInSleep)
30 Require (seconds2Wait >= 0.0s);
34#if qStroika_Foundation_Common_Platform_POSIX
35 if constexpr (qStroika_Foundation_Common_Platform_POSIX) {
36 constexpr long kNanoSecondsPerSecond = 1000L * 1000L * 1000L;
38 ts.tv_sec = seconds2Wait.As<time_t> ();
39 ts.tv_nsec =
static_cast<long> (kNanoSecondsPerSecond * (seconds2Wait.As<
double> () - ts.tv_sec));
40 Assert (0 <= ts.tv_sec);
41 Assert (0 <= ts.tv_nsec and ts.tv_nsec < kNanoSecondsPerSecond);
43 int nanoSleepResult = ::nanosleep (&ts, &nextTS);
46#if _POSIX_C_SOURCE >= 200809L
47 if (nanoSleepResult < 0 and errno == EINVAL) {
48 if ((errno = ::clock_nanosleep (CLOCK_MONOTONIC, 0, &ts, &nextTS)) == 0) {
53 if (nanoSleepResult == 0) {
54 *remainingInSleep = 0s;
57 Assert (errno == EINTR);
60 WeakAssert (0 <= nextTS.tv_nsec and nextTS.tv_nsec < kNanoSecondsPerSecond);
63 Time::DurationSeconds{nextTS.tv_sec +
static_cast<Time::DurationSeconds::rep
> (nextTS.tv_nsec) / kNanoSecondsPerSecond};
66#elif qStroika_Foundation_Common_Platform_Windows
67 if constexpr (qStroika_Foundation_Common_Platform_Windows) {
68 Time::TimePointSeconds tc = Time::GetTickCount ();
69 if (::SleepEx (
static_cast<int> (seconds2Wait.count () * 1000),
true) == 0) {
70 *remainingInSleep = 0s;
73 Time::DurationSeconds remaining = (tc + seconds2Wait) - Time::GetTickCount ();
77 *remainingInSleep = remaining;
83 Ensure (*remainingInSleep <= seconds2Wait);
84 Ensure (*remainingInSleep >= 0s);
100 Require (seconds2Wait >= 0s);
101 SleepUntil (Time::GetTickCount () + seconds2Wait);
#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...
Duration is a chrono::duration<double> (=.
void CheckForInterruption()
void Sleep(Time::Duration seconds2Wait)
void SleepUntil(Time::TimePointSeconds untilTickCount)