You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/12/14 03:16:30 UTC

[incubator-nuttx] branch master updated: wqueue: update wqueue to support using wqueue before wqueue start

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 166a921  wqueue: update wqueue to support using wqueue before wqueue start
166a921 is described below

commit 166a9210ca33a447b55ec75f5da1d6ac0ee60c43
Author: ligd <li...@xiaomi.com>
AuthorDate: Wed Dec 1 23:40:16 2021 +0800

    wqueue: update wqueue to support using wqueue before wqueue start
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 include/nuttx/semaphore.h   | 15 +++++++++++++++
 sched/wqueue/kwork_thread.c | 17 ++++++++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h
index 83fb3c1..c9e488c 100644
--- a/include/nuttx/semaphore.h
+++ b/include/nuttx/semaphore.h
@@ -36,6 +36,21 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Initializers */
+
+#ifdef CONFIG_PRIORITY_INHERITANCE
+# if CONFIG_SEM_PREALLOCHOLDERS > 0
+#  define NXSEM_INITIALIZER(c, f) \
+    {(c), (f), NULL}                    /* semcount, flags, hhead */
+# else
+#  define NXSEM_INITIALIZER(c, f) \
+    {(c), (f), {{NULL, 0}, {NULL, 0}}}  /* semcount, flags, holder[2] */
+# endif
+#else /* CONFIG_PRIORITY_INHERITANCE */
+#  define NXSEM_INITIALIZER(c, f) \
+    {(c)}                               /* semcount, flags */
+#endif /* CONFIG_PRIORITY_INHERITANCE */
+
 /* Most internal nxsem_* interfaces are not available in the user space in
  * PROTECTED and KERNEL builds.  In that context, the application semaphore
  * interfaces must be used.  The differences between the two sets of
diff --git a/sched/wqueue/kwork_thread.c b/sched/wqueue/kwork_thread.c
index 2e48399..18c9a71 100644
--- a/sched/wqueue/kwork_thread.c
+++ b/sched/wqueue/kwork_thread.c
@@ -73,13 +73,23 @@
 #if defined(CONFIG_SCHED_HPWORK)
 /* The state of the kernel mode, high priority work queue(s). */
 
-struct hp_wqueue_s g_hpwork;
+struct hp_wqueue_s g_hpwork =
+{
+  {},
+  NXSEM_INITIALIZER(0, SEM_PRIO_NONE),
+};
+
 #endif /* CONFIG_SCHED_HPWORK */
 
 #if defined(CONFIG_SCHED_LPWORK)
 /* The state of the kernel mode, low priority work queue(s). */
 
-struct lp_wqueue_s g_lpwork;
+struct lp_wqueue_s g_lpwork =
+{
+  {},
+  NXSEM_INITIALIZER(0, SEM_PRIO_NONE),
+};
+
 #endif /* CONFIG_SCHED_LPWORK */
 
 /****************************************************************************
@@ -203,9 +213,6 @@ static int work_thread_create(FAR const char *name, int priority,
   argv[0] = args;
   argv[1] = NULL;
 
-  nxsem_init(&wqueue->sem, 0, 0);
-  nxsem_set_protocol(&wqueue->sem, SEM_PRIO_NONE);
-
   /* Don't permit any of the threads to run until we have fully initialized
    * g_hpwork and g_lpwork.
    */