| 1 | // Copyright 2007 - 2021, Alan Antonuk and the rabbitmq-c contributors. |
| 2 | // SPDX-License-Identifier: mit |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <sys/time.h> |
| 6 | #include <time.h> |
| 7 | #include <unistd.h> |
| 8 | |
| 9 | uint64_t now_microseconds(void) { |
| 10 | struct timeval tv; |
| 11 | gettimeofday(&tv, NULL); |
| 12 | return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec; |
| 13 | } |
| 14 | |
| 15 | void microsleep(int usec) { |
| 16 | struct timespec req; |
| 17 | req.tv_sec = 0; |
| 18 | req.tv_nsec = 1000 * usec; |
| 19 | nanosleep(&req, NULL); |
| 20 | } |