This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new c9bc7af3f84 sched/wqueue: Return zero from work_timeleft() once the
work expired.
c9bc7af3f84 is described below
commit c9bc7af3f84d46042914f078f83aadfb7eb951d8
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Wed Nov 25 10:26:15 2026 +0800
sched/wqueue: Return zero from work_timeleft() once the work expired.
work_timeleft() subtracted the current tick from the expiry of the work,
so a work that has expired but not run yet, for example while all the
workers are busy, gave a negative time left. Its description says that
zero means that the work has already started. Return zero once the
expiry is reached, and read the clock only once.
Signed-off-by: ouyangxiangzhen <[email protected]>
Signed-off-by: ganjing <[email protected]>
---
include/nuttx/wqueue.h | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h
index 5c0b7ee9c06..c489aaef201 100644
--- a/include/nuttx/wqueue.h
+++ b/include/nuttx/wqueue.h
@@ -634,12 +634,17 @@ int work_cancel_sync_wq(FAR struct kwork_wqueue_s *wqueue,
*
****************************************************************************/
+static inline_function clock_t work_timeleft(FAR const struct work_s *work)
+{
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
-# define work_timeleft(work) ((work)->qtime - clock_systime_ticks())
+ clock_t now = clock_systime_ticks();
#else
-# define work_timeleft(work) ((work)->qtime - CLOCK2TICK(clock()))
+ clock_t now = CLOCK2TICK(clock());
#endif
+ return clock_compare(work->qtime, now) ? 0 : work->qtime - now;
+}
+
/****************************************************************************
* Name: lpwork_boostpriority
*