diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h index 659f1b8596a..7ab1e81e051 100644 --- a/include/nuttx/wqueue.h +++ b/include/nuttx/wqueue.h @@ -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 * diff --git a/sched/wqueue/kwork_thread.c b/sched/wqueue/kwork_thread.c index 6a6cb025d71..847d26283b5 100644 --- a/sched/wqueue/kwork_thread.c +++ b/sched/wqueue/kwork_thread.c @@ -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 * diff --git a/sched/wqueue/wqueue.h b/sched/wqueue/wqueue.h index 774cebcda2b..399a3fbddc7 100644 --- a/sched/wqueue/wqueue.h +++ b/sched/wqueue/wqueue.h @@ -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 */