mirror of
https://github.com/apache/nuttx.git
synced 2026-10-06 13:55:15 +00:00
wqueue: improve the robustness of the work
struct work_s
{
union
{
struct
{
struct dq_entry_s dq; /* Implements a double linked list */
clock_t qtime; /* Time work queued */
} s;
struct wdog_s timer; /* Delay expiry timer */
struct wdog_period_s ptimer; /* Period expiry timer */
} u;
worker_t worker; /* Work callback */
FAR void *arg; /* Callback argument */
FAR struct kwork_wqueue_s *wq; /* Work queue */
};
work_cancel() should determine whether the current work is
in the timer or has already entered the queue.
This judgment is indispensable because the structure is a union.
Whether it is interpreted as a timer or as a dq needs to be determined.
But this judgment seriously depends on the order of struct wdog_s and
struct dq_entry_s, once someone change the order of any, there is a bug.
So we decide remove the union, to improve the robustness.
For the work_s structure size will grow bigger, then we will provide a
another optimization patch
Signed-off-by: ligd <liguiding1@xiaomi.com>
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
parent
c22df41ca6
commit
900b1c19dd
5 changed files with 16 additions and 28 deletions
|
|
@ -72,12 +72,7 @@ struct wdlist_node
|
|||
FAR struct wdlist_node *next;
|
||||
};
|
||||
|
||||
/* This is the internal representation of the watchdog timer structure.
|
||||
* Notice !!!
|
||||
* Carefully with the struct wdog_s order, you may not directly modify
|
||||
* this. This struct will combine in struct work_s in union type, and,
|
||||
* wqueue will modify/check this struct in kwork work_qcancel().
|
||||
*/
|
||||
/* Support a doubly linked list of watchdog timers */
|
||||
|
||||
struct wdog_s
|
||||
{
|
||||
|
|
@ -87,7 +82,7 @@ struct wdog_s
|
|||
#ifdef CONFIG_PIC
|
||||
FAR void *picbase; /* PIC base address */
|
||||
#endif
|
||||
clock_t expired; /* Timer associated with the absoulute time */
|
||||
clock_t expired; /* Timer associated with the absolute time */
|
||||
};
|
||||
|
||||
struct wdog_period_s
|
||||
|
|
@ -168,7 +163,7 @@ int wd_start(FAR struct wdog_s *wdog, sclock_t delay,
|
|||
*
|
||||
* Input Parameters:
|
||||
* wdog - Watchdog ID
|
||||
* ticks - Absoulute time in clock ticks
|
||||
* ticks - Absolute time in clock ticks
|
||||
* wdentry - Function to call on timeout
|
||||
* arg - Parameter to pass to wdentry.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -249,13 +249,10 @@ typedef CODE void (*worker_t)(FAR void *arg);
|
|||
|
||||
struct work_s
|
||||
{
|
||||
struct dq_entry_s dq; /* Implements a double linked list */
|
||||
clock_t qtime; /* Time work queued */
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
struct dq_entry_s dq; /* Implements a double linked list */
|
||||
clock_t qtime; /* Time work queued */
|
||||
} s;
|
||||
struct wdog_s timer; /* Delay expiry timer */
|
||||
struct wdog_period_s ptimer; /* Period expiry timer */
|
||||
} u;
|
||||
|
|
@ -560,11 +557,7 @@ int work_cancel_sync_wq(FAR struct kwork_wqueue_s *wqueue,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __KERNEL__
|
||||
# define work_timeleft(work) wd_gettime(&((work)->u.timer))
|
||||
#else
|
||||
# define work_timeleft(work) ((sclock_t)((work)->u.s.qtime - clock()))
|
||||
#endif
|
||||
#define work_timeleft(work) ((sclock_t)((work)->qtime - clock()))
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpwork_boostpriority
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue