GetTickCount() аналоги?
static int timer = 0;
if ( GetTickCount() - timer > 30000 ) //1 раз в 30 секунд
{
//code
timer = GetTickCount();
}
Привет друзья, подскажите как реализовать аналог для си линукс? именно такой тип
Ответы (1 шт):
Автор решения: Arty
→ Ссылка
Как @avp уже сказал, можно использовать clock_gettime(...).
#include <stdint.h>
#include <time.h>
#include <stdio.h>
uint32_t GetTickCount() {
enum {
#ifdef CLOCK_BOOTTIME
boot_time_id = CLOCK_BOOTTIME
#else
boot_time_id = 7
#endif
};
struct timespec spec;
clock_gettime(boot_time_id, &spec);
return (uint32_t)(((uint64_t)spec.tv_sec) * 1000 + ((uint64_t)spec.tv_nsec) / 1000000);
}
int main() {
printf("UpTime: %u ms\n", GetTickCount());
return 0;
}
Пример вывода:
UpTime: 489962023 ms