23 #define _POSIX_C_SOURCE 199309L
34 unsigned long long elapsed;
35 unsigned long sec_factor;
37 unsigned long _missed;
39 clock_gettime(CLOCK_REALTIME, &now);
43 sec_factor = 1000 * 1000 * 1000;
46 sec_factor = 1000 * 1000;
57 nan_factor = 1000 * 1000 * 1000 / sec_factor;
58 elapsed = (now.tv_sec - this->sec) * sec_factor
59 + (now.tv_nsec - this->nsec) / nan_factor;
61 _missed = elapsed / this->timeout;
63 this->sec += _missed * this->timeout * sec_factor / nan_factor;
64 this->nsec += _missed * this->timeout * sec_factor % nan_factor;
65 if (missed) *missed = _missed;
67 if (missed) *missed = 0;
70 return this->timeout - (elapsed % this->timeout);
unsigned long TR_timerGet(TR_Timer this, unsigned long *missed)