workqueue: add work_foreach support

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2022-01-24 18:17:50 +08:00 committed by Xiang Xiao
parent b53bbb15c5
commit d09be7d658
3 changed files with 72 additions and 4 deletions

View file

@ -292,6 +292,10 @@ struct work_notifier_s
worker_t worker; /* The worker function to schedule */
};
/* This is the callback type used by work_foreach() */
typedef CODE void (*work_foreach_t)(int tid, FAR void *arg);
/****************************************************************************
* Public Data
****************************************************************************/
@ -381,6 +385,25 @@ int work_queue(int qid, FAR struct work_s *work, worker_t worker,
int work_cancel(int qid, FAR struct work_s *work);
/****************************************************************************
* Name: work_foreach
*
* Description:
* Enumerate over each work thread and provide the tid of each task to a
* user callback functions.
*
* Input Parameters:
* qid - The work queue ID
* handler - The function to be called with the pid of each task
* arg - The function callback
*
* Returned Value:
* None
*
****************************************************************************/
void work_foreach(int qid, work_foreach_t handler, FAR void *arg);
/****************************************************************************
* Name: work_available
*

View file

@ -232,9 +232,7 @@ static int work_thread_create(FAR const char *name, int priority,
return pid;
}
#ifdef CONFIG_PRIORITY_INHERITANCE
wqueue->worker[wndx].pid = pid;
#endif
}
sched_unlock();
@ -245,6 +243,55 @@ static int work_thread_create(FAR const char *name, int priority,
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: work_foreach
*
* Description:
* Enumerate over each work thread and provide the tid of each task to a
* user callback functions.
*
* Input Parameters:
* qid - The work queue ID
* handler - The function to be called with the pid of each task
* arg - The function callback
*
* Returned Value:
* None
*
****************************************************************************/
void work_foreach(int qid, work_foreach_t handler, FAR void *arg)
{
FAR struct kwork_wqueue_s *wqueue;
int nthread;
int wndx;
#ifdef CONFIG_SCHED_HPWORK
if (qid == HPWORK)
{
wqueue = (FAR struct kwork_wqueue_s *)&g_hpwork;
nthread = CONFIG_SCHED_HPNTHREADS;
}
else
#endif
#ifdef CONFIG_SCHED_LPWORK
if (qid == LPWORK)
{
wqueue = (FAR struct kwork_wqueue_s *)&g_lpwork;
nthread = CONFIG_SCHED_LPNTHREADS;
}
else
#endif
{
return;
}
for (wndx = 0; wndx < nthread; wndx++)
{
handler(wqueue->worker[wndx].pid, arg);
}
}
/****************************************************************************
* Name: work_start_highpri
*

View file

@ -51,9 +51,7 @@
struct kworker_s
{
#ifdef CONFIG_PRIORITY_INHERITANCE
pid_t pid; /* The task ID of the worker thread */
#endif
};
/* This structure defines the state of one kernel-mode work queue */