/* Generated by zi2c from timer_linux.zi. */ #define ZIRAN_TIMER_LINUX_H_SOURCE 1 #include #include #include #include "timer_linux.h" int64_t MonotonicNanoseconds(void) { zir_9339a8296a493286_ClockValue value = {0}; if (zir_f_9bb5b5b3425765c7_ClockGetTimeRaw(1, &(value)) != 0) { return -1LL; } int64_t seconds = (int64_t)(value.seconds); int64_t nanoseconds = (int64_t)(value.nanoseconds); if (seconds < 0LL || nanoseconds < 0LL || nanoseconds > 999999999LL || seconds > 9223372036LL || (seconds == 9223372036LL && nanoseconds > 854775807LL)) { return -1LL; } return (int64_t)(((uint64_t)seconds * UINT64_C(1000000000)) + (uint64_t)nanoseconds); } int64_t MonotonicMilliseconds(void) { zir_9339a8296a493286_ClockValue value[1] = {0}; if (zir_f_9bb5b5b3425765c7_ClockGetTimeRaw(1, &(value[0])) != 0) { return -1LL; } int64_t seconds = (int64_t)((value[0]).seconds); int64_t nanoseconds = (int64_t)((value[0]).nanoseconds); if (nanoseconds < 0LL || nanoseconds > 999999999LL) { return -1LL; } if (seconds > 9223372036854775LL || seconds < 0LL) { return -1LL; } return (int64_t)(((uint64_t)seconds * UINT64_C(1000)) + (uint64_t)((nanoseconds / 1000000LL))); } zir_9339a8296a493286_ClockValue timer_linux_MakeClockValue(int64_t milliseconds) { zir_9339a8296a493286_ClockValue value = {0}; if (milliseconds < 0LL) { return value; } ptrdiff_t* value_0 = &(value.seconds); (*value_0) = (ptrdiff_t)((milliseconds / 1000LL)); ptrdiff_t* value_1 = &(value.nanoseconds); (*value_1) = (ptrdiff_t)(((int64_t)((uint64_t)((milliseconds % 1000LL)) * UINT64_C(1000000)))); return value; } bool SleepMilliseconds(int64_t milliseconds) { if (milliseconds < 0LL || milliseconds > 86400000LL) { return false; } zir_9339a8296a493286_ClockValue request[1] = {0}; zir_9339a8296a493286_ClockValue remaining[1] = {0}; zir_9339a8296a493286_ClockValue* value_0 = &(request[0]); int64_t value_1 = milliseconds; zir_9339a8296a493286_ClockValue value_2 = {0}; { int64_t milliseconds = value_1; zir_9339a8296a493286_ClockValue value = {0}; if (milliseconds < 0LL) { value_2 = value; goto value_3; } ptrdiff_t* value_4 = &(value.seconds); (*value_4) = (ptrdiff_t)((milliseconds / 1000LL)); ptrdiff_t* value_5 = &(value.nanoseconds); (*value_5) = (ptrdiff_t)(((int64_t)((uint64_t)((milliseconds % 1000LL)) * UINT64_C(1000000)))); value_2 = value; value_3: ; } (*value_0) = value_2; while ((request[0]).seconds > 0 || (request[0]).nanoseconds > 0) { int32_t status = zir_f_9bb5b5b3425765c7_ClockSleepRaw(1, 0, &(request[0]), &(remaining[0])); if (status == 0) { return true; } if (status != 4) { return false; } zir_9339a8296a493286_ClockValue* value_6 = &(request[0]); (*value_6) = (remaining)[0]; } return true; }