mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Use monotonic clock in os_tick_ms and os_tick_sec on POSIX systems
This commit is contained in:
parent
cdd8798227
commit
fa8913a759
1 changed files with 29 additions and 1 deletions
30
os/unix.c
30
os/unix.c
|
|
@ -1674,6 +1674,17 @@ uint64_t os_tick(void)
|
|||
|
||||
uint64_t os_tick_ms(void)
|
||||
{
|
||||
#if HAVE_CLOCK_GETTIME && defined(CLOCK_MONOTONIC)
|
||||
struct timespec ts;
|
||||
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
return ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
|
||||
#else
|
||||
struct timeval tv;
|
||||
|
||||
if (gettimeofday(&tv, 0) != 0) {
|
||||
|
|
@ -1683,15 +1694,32 @@ uint64_t os_tick_ms(void)
|
|||
}
|
||||
|
||||
return tv.tv_sec * 1000ULL + tv.tv_usec / 1000;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t os_tick_sec(void)
|
||||
{
|
||||
#if HAVE_CLOCK_GETTIME && defined(CLOCK_MONOTONIC)
|
||||
struct timespec ts;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
return ts.tv_sec;
|
||||
#else
|
||||
struct timeval tv;
|
||||
|
||||
if (gettimeofday(&tv, 0) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
return tv.tv_sec;
|
||||
#endif
|
||||
}
|
||||
|
||||
int os_usleep(uint64_t usec)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue