mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
wqueue: optimize work_s structure
Change-Id: I908ac2fcead3a6fed3078b2339392ed93d2e4809 Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
@@ -245,14 +245,17 @@ typedef CODE void (*worker_t)(FAR void *arg);
|
||||
|
||||
struct work_s
|
||||
{
|
||||
struct sq_entry_s sq; /* Implements a single linked list */
|
||||
union
|
||||
{
|
||||
struct wdog_s timer; /* Delay expiry timer */
|
||||
clock_t qtime; /* Time work queued */
|
||||
struct
|
||||
{
|
||||
struct sq_entry_s sq; /* Implements a single linked list */
|
||||
clock_t qtime; /* Time work queued */
|
||||
} s;
|
||||
struct wdog_s timer; /* Delay expiry timer */
|
||||
} u;
|
||||
worker_t worker; /* Work callback */
|
||||
FAR void *arg; /* Callback argument */
|
||||
worker_t worker; /* Work callback */
|
||||
FAR void *arg; /* Callback argument */
|
||||
};
|
||||
|
||||
/* This is an enumeration of the various events that may be
|
||||
|
||||
@@ -87,7 +87,7 @@ static int work_qcancel(FAR struct usr_wqueue_s *wqueue,
|
||||
*/
|
||||
|
||||
curr = wqueue->q.head;
|
||||
while (curr && curr != &work->sq)
|
||||
while (curr && curr != &work->u.s.sq)
|
||||
{
|
||||
prev = curr;
|
||||
curr = curr->flink;
|
||||
|
||||
@@ -86,9 +86,9 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue,
|
||||
|
||||
/* Initialize the work structure */
|
||||
|
||||
work->worker = worker; /* Work callback. non-NULL means queued */
|
||||
work->arg = arg; /* Callback argument */
|
||||
work->u.qtime = clock() + delay; /* Delay until work performed */
|
||||
work->worker = worker; /* Work callback. non-NULL means queued */
|
||||
work->arg = arg; /* Callback argument */
|
||||
work->u.s.qtime = clock() + delay; /* Delay until work performed */
|
||||
|
||||
/* Do the easy case first -- when the work queue is empty. */
|
||||
|
||||
@@ -96,7 +96,7 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue,
|
||||
{
|
||||
/* Add the watchdog to the head == tail of the queue. */
|
||||
|
||||
sq_addfirst(&work->sq, &wqueue->q);
|
||||
sq_addfirst(&work->u.s.sq, &wqueue->q);
|
||||
_SEM_POST(&wqueue->wake);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue,
|
||||
|
||||
do
|
||||
{
|
||||
delta = work->u.qtime - ((FAR struct work_s *)curr)->u.qtime;
|
||||
delta = work->u.s.qtime - ((FAR struct work_s *)curr)->u.s.qtime;
|
||||
if (delta < 0)
|
||||
{
|
||||
break;
|
||||
@@ -127,7 +127,7 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue,
|
||||
{
|
||||
/* Insert the watchdog at the head of the list */
|
||||
|
||||
sq_addfirst(&work->sq, &wqueue->q);
|
||||
sq_addfirst(&work->u.s.sq, &wqueue->q);
|
||||
_SEM_GETVALUE(&wqueue->wake, &semcount);
|
||||
if (semcount < 1)
|
||||
{
|
||||
@@ -138,7 +138,7 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue,
|
||||
{
|
||||
/* Insert the watchdog in mid- or end-of-queue */
|
||||
|
||||
sq_addafter(prev, &work->sq, &wqueue->q);
|
||||
sq_addafter(prev, &work->u.s.sq, &wqueue->q);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ static void work_process(FAR struct usr_wqueue_s *wqueue)
|
||||
* zero will always execute immediately.
|
||||
*/
|
||||
|
||||
elapsed = clock() - work->u.qtime;
|
||||
elapsed = clock() - work->u.s.qtime;
|
||||
|
||||
/* Is this delay work ready? */
|
||||
|
||||
@@ -173,7 +173,7 @@ static void work_process(FAR struct usr_wqueue_s *wqueue)
|
||||
}
|
||||
else
|
||||
{
|
||||
next = work->u.qtime - clock();
|
||||
next = work->u.s.qtime - clock();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user