From 9d2dae2fd8b5b6848a9af1c39688e417e9a4503f Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Thu, 19 May 2022 01:09:34 +0800 Subject: [PATCH] sched/wqueue: Add work_timeleft macro to get the left time to start Signed-off-by: Xiang Xiao --- include/nuttx/wqueue.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h index bd910687485..5bdc25e22ef 100644 --- a/include/nuttx/wqueue.h +++ b/include/nuttx/wqueue.h @@ -421,6 +421,29 @@ void work_foreach(int qid, work_foreach_t handler, FAR void *arg); #define work_available(work) ((work)->worker == NULL) +/**************************************************************************** + * Name: work_timeleft + * + * Description: + * This function returns the time remaining before the specified work + * start. + * + * Input Parameters: + * work - The work queue structure to check. + * + * Returned Value: + * The time in system ticks remaining until the work start. + * Zero means either that work is not valid or that work has already + * started. + * + ****************************************************************************/ + +#ifdef __KERNEL__ +# define work_timeleft(work) wd_gettime(&((work)->u.timer)) +#else +# define work_timeleft(work) ((sclock_t)((work)->u.s.qtime - clock())) +#endif + /**************************************************************************** * Name: lpwork_boostpriority *