From 78ca034252a584fd44d44592b91abc903e453727 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Wed, 10 Oct 2018 15:06:17 +0200 Subject: [PATCH] lib: add thread_timer_remain_msec function Signed-off-by: Christian Franke --- lib/thread.c | 12 +++++++++--- lib/thread.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/thread.c b/lib/thread.c index d104c4f598..44c9e2b2f1 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -655,20 +655,26 @@ void thread_master_free(struct thread_master *m) XFREE(MTYPE_THREAD_MASTER, m); } -/* Return remain time in second. */ -unsigned long thread_timer_remain_second(struct thread *thread) +/* Return remain time in miliseconds. */ +unsigned long thread_timer_remain_msec(struct thread *thread) { int64_t remain; pthread_mutex_lock(&thread->mtx); { - remain = monotime_until(&thread->u.sands, NULL) / 1000000LL; + remain = monotime_until(&thread->u.sands, NULL) / 1000LL; } pthread_mutex_unlock(&thread->mtx); return remain < 0 ? 0 : remain; } +/* Return remain time in seconds. */ +unsigned long thread_timer_remain_second(struct thread *thread) +{ + return thread_timer_remain_msec(thread) / 1000LL; +} + #define debugargdef const char *funcname, const char *schedfrom, int fromln #define debugargpass funcname, schedfrom, fromln diff --git a/lib/thread.h b/lib/thread.h index 4de9a65562..f404d92755 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -217,6 +217,7 @@ extern struct thread *thread_fetch(struct thread_master *, struct thread *); extern void thread_call(struct thread *); extern unsigned long thread_timer_remain_second(struct thread *); extern struct timeval thread_timer_remain(struct thread *); +extern unsigned long thread_timer_remain_msec(struct thread *); extern int thread_should_yield(struct thread *); /* set yield time for thread */ extern void thread_set_yield_time(struct thread *, unsigned long); -- 2.39.5