This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new d09be7d workqueue: add work_foreach support
d09be7d is described below
commit d09be7d65836f8aa4cfb3fd4b9d792113741b15e
Author: ligd <[email protected]>
AuthorDate: Mon Jan 24 18:17:50 2022 +0800
workqueue: add work_foreach support
Signed-off-by: ligd <[email protected]>
---
include/nuttx/wqueue.h | 23 ++++++++++++++++++++
sched/wqueue/kwork_thread.c | 51 +++++++++++++++++++++++++++++++++++++++++++--
sched/wqueue/wqueue.h | 2 --
3 files changed, 72 insertions(+), 4 deletions(-)
diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h
index 659f1b8..7ab1e81 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
****************************************************************************/
@@ -382,6 +386,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
*
* Description:
diff --git a/sched/wqueue/kwork_thread.c b/sched/wqueue/kwork_thread.c
index 6a6cb02..847d262 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();
@@ -246,6 +244,55 @@ static int work_thread_create(FAR const char *name, int
priority,
****************************************************************************/
/****************************************************************************
+ * 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
*
* Description:
diff --git a/sched/wqueue/wqueue.h b/sched/wqueue/wqueue.h
index 774cebc..399a3fb 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 */