Bool SemaImplementationTimedWait(void* Data, const TimeSpan& timeout) { timeval t; gettimeofday(&t, 0); RF_Type::UInt64 end = t.tv_sec * 10000000llu + t.tv_usec * 10llu + timeout.Ticks(); timespec atTime; atTime.tv_sec = end / TimeSpan::TicksPerSecond; atTime.tv_nsec = end - atTime.tv_sec * TimeSpan::TicksPerSecond; #ifdef RF_OSX time_t timer = time(NULL) * 1000 + end; int res = 0; do { res = sem_trywait(static_cast<sem_t*>(Data)); if(res == 0) break; sleep(1); } while(time(NULL) * 1000 < timer); #else int res = sem_timedwait(static_cast<sem_t*>(Data), &atTime); #endif return res == 0; }
void Thread::Sleep(TimeSpan timeout) { if(timeout == TimeSpan::Zero) return; //! no reason to sleep LARGE_INTEGER pli; pli.QuadPart = -timeout.Ticks(); KeDelayExecutionThread((KPROCESSOR_MODE)0, FALSE, &pli); }
constexpr TimeSpan operator-(TimeSpan ts) { return TimeSpan(-ts.Ticks()); }
constexpr TimeSpan operator-(TimeSpan a, TimeSpan b) { return TimeSpan(a.Ticks() - b.Ticks()); }
constexpr bool operator>=(TimeSpan a, TimeSpan b) { return a.Ticks() >= b.Ticks(); }
constexpr bool operator<(TimeSpan a, TimeSpan b) { return a.Ticks() < b.Ticks(); }