From 68eb4fbc022c37c070757841322646ab9b381e7b Mon Sep 17 00:00:00 2001 From: zfx Date: Fri, 9 Jul 2021 16:31:49 +0800 Subject: [PATCH] modify OsalGetTime implementation from do_gettimeofday to clock_gettime Signed-off-by: zfx --- support/posix/src/osal_time.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/support/posix/src/osal_time.c b/support/posix/src/osal_time.c index 12bec4d58..dbd65d0f9 100644 --- a/support/posix/src/osal_time.c +++ b/support/posix/src/osal_time.c @@ -18,20 +18,17 @@ int32_t OsalGetTime(OsalTimespec *time) { - struct timeval tv; + struct timespec ts; if (time == NULL) { HDF_LOGE("%s invalid para", __func__); return HDF_ERR_INVALID_PARAM; } - (void)memset_s(&tv, sizeof(tv), 0, sizeof(tv)); - if (gettimeofday(&tv, NULL) != 0) { - HDF_LOGE("%s gettimeofday failed", __func__); - return HDF_FAILURE; - } - time->sec = tv.tv_sec; - time->usec = tv.tv_usec; + (void)memset_s(&ts, sizeof(ts), 0, sizeof(ts)); + clock_gettime(CLOCK_MONOTONIC, &ts); + time->sec = ts.tv_sec; + time->usec = ts.tv_nsec / HDF_KILO_UNIT; return HDF_SUCCESS; } @@ -90,13 +87,10 @@ void OsalMDelay(uint32_t ms) uint64_t OsalGetSysTimeMs() { - struct timeval tv; + OsalTimespec time; - (void)memset_s(&tv, sizeof(tv), 0, sizeof(tv)); - if (gettimeofday(&tv, NULL) != 0) { - HDF_LOGE("%s gettimeofday failed", __func__); - return 0; - } + (void)memset_s(&time, sizeof(time), 0, sizeof(time)); + (void)OsalGetTime(&time); - return ((uint64_t)tv.tv_sec * HDF_KILO_UNIT + tv.tv_usec / HDF_KILO_UNIT); + return (time.sec * HDF_KILO_UNIT + time.usec / HDF_KILO_UNIT); } -- Gitee