From 3e192fae09906cb3f755c29fd333cd6ab9beb7ac Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Fri, 11 Dec 2020 11:36:12 +0800 Subject: [PATCH] fc_timedwait_ms must call get_current_time_ms() --- src/pthread_func.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pthread_func.h b/src/pthread_func.h index 525a6f6..53a0f5d 100644 --- a/src/pthread_func.h +++ b/src/pthread_func.h @@ -23,8 +23,9 @@ #include #include #include "common_define.h" -#include "logger.h" +#include "shared_func.h" #include "sched_thread.h" +#include "logger.h" #ifdef __cplusplus extern "C" { @@ -83,11 +84,13 @@ static inline void fc_timedwait_sec(pthread_mutex_t *lock, static inline void fc_timedwait_ms(pthread_mutex_t *lock, pthread_cond_t *cond, const int timeout_ms) { + int64_t expires_ms; struct timespec ts; + expires_ms = get_current_time_ms() + timeout_ms; PTHREAD_MUTEX_LOCK(lock); - ts.tv_sec = get_current_time() + timeout_ms / 1000; - ts.tv_nsec = (timeout_ms % 1000) * (1000 * 1000); + ts.tv_sec = expires_ms / 1000; + ts.tv_nsec = (expires_ms % 1000) * (1000 * 1000); pthread_cond_timedwait(cond, lock, &ts); PTHREAD_MUTEX_UNLOCK(lock); }