25 #if defined(__APPLE__) 26 #include <mach/mach_time.h> 34 #define gettime_ms __gettime_ms 35 inline int64_t __gettime_ms()
37 #if defined(__APPLE__) 40 static mach_timebase_info_data_t timebase;
42 if (timebase.denom == 0)
43 (void)mach_timebase_info(&timebase);
45 ticks = mach_absolute_time() * timebase.numer / timebase.denom;
46 return ticks / 1000000;
47 #elif defined(__WINDOWS__) 48 LARGE_INTEGER tickPerSecond;
50 if (QueryPerformanceFrequency(&tickPerSecond))
52 QueryPerformanceCounter(&tick);
53 return (int64_t) (tick.QuadPart / (tickPerSecond.QuadPart / 1000.0));
58 clock_gettime(CLOCK_MONOTONIC, &time);
59 return (int64_t)time.tv_sec * 1000 + time.tv_nsec / 1000000;
67 CTimeout(
unsigned millisec) : m_time(0) { Set(millisec); }
69 void Set(
unsigned millisec)
71 m_time = gettime_ms() + millisec;
76 return (m_time > 0 ?
true :
false);
84 unsigned TimeLeft()
const 86 int64_t time = gettime_ms();
87 return (time > m_time ? 0 : static_cast<unsigned>(m_time - time));
90 bool operator==(
const CTimeout& other)
const 92 return m_time == other.m_time;
95 bool operator!=(
const CTimeout& other)
const 97 return m_time != other.m_time;
100 bool operator<(
const CTimeout& other)
const 102 return m_time < other.m_time;
105 bool operator>(
const CTimeout& other)
const 107 return m_time > other.m_time;
110 bool operator>=(
const CTimeout& other)
const 112 return !(m_time < other.m_time);
115 bool operator<=(
const CTimeout& other)
const 117 return !(m_time > other.m_time);