diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index 83fb3c12b4f..c9e488c3fdb 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 2e4839922ce..18c9a7143de 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. */