summaryrefslogtreecommitdiff
path: root/nuttx/include/nuttx/wqueue.h
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-10-10 08:35:58 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-10-10 08:35:58 -0600
commit1c1cdb89c3242461047d5b63430fa28090a9a65f (patch)
treedb8ec3f0e62f1a8e18aa8bfb1194c553e3d96dd1 /nuttx/include/nuttx/wqueue.h
parent9b9ec70ae1cc4560810677c6499a35be6ce8c614 (diff)
downloadnuttx-1c1cdb89c3242461047d5b63430fa28090a9a65f.tar.gz
nuttx-1c1cdb89c3242461047d5b63430fa28090a9a65f.tar.bz2
nuttx-1c1cdb89c3242461047d5b63430fa28090a9a65f.zip
Decoupling work queue data structures. This is part of the preparation to support multiple low-priority worker threads
Diffstat (limited to 'nuttx/include/nuttx/wqueue.h')
-rw-r--r--nuttx/include/nuttx/wqueue.h117
1 files changed, 46 insertions, 71 deletions
diff --git a/nuttx/include/nuttx/wqueue.h b/nuttx/include/nuttx/wqueue.h
index cad35a56d..8af1c938f 100644
--- a/nuttx/include/nuttx/wqueue.h
+++ b/nuttx/include/nuttx/wqueue.h
@@ -169,6 +169,8 @@
# define CONFIG_SCHED_WORKSTACKSIZE CONFIG_IDLETHREAD_STACKSIZE
# endif
+#endif /* CONFIG_SCHED_HPWORK */
+
/* Low priority kernel work queue configuration *****************************/
#ifdef CONFIG_SCHED_LPWORK
@@ -215,7 +217,6 @@
#endif
#endif /* CONFIG_SCHED_LPWORK */
-#endif /* CONFIG_SCHED_HPWORK */
/* User space work queue configuration **************************************/
@@ -235,58 +236,42 @@
#endif /* CONFIG_SCHED_USRWORK */
-/* How many worker threads are there? In the user-space phase of a kernel
- * build, there will be no more than one.
+/* Work queue IDs:
*
- * Work queue IDs (indices):
+ * Kernel Work Queues:
+ * HPWORK: This ID of the high priority work queue that should only be
+ * used for hi-priority, time-critical, driver bottom-half functions.
*
- * Kernel Work Queues: There are none and any attempts to use them
- * should generate errors.
+ * LPWORK: This is the ID of the low priority work queue that can be
+ * used for any purpose. if CONFIG_SCHED_LPWORK is not defined, then
+ * there is only one kernel work queue and LPWORK == HPWORK.
*
- * User Work Queue: Will be available if CONFIG_SCHED_USRWORK is defined
+ * User Work Queue:
+ * USRWORK: In the kernel phase a a kernel build, there should be no
+ * references to user-space work queues. That would be an error.
+ * Otherwise, in a flat build, user applications will use the lower
+ * priority work queue (if there is one).
*/
-#if defined(CONFIG_BUILD_PROTECTED) && !defined(__KERNEL__)
-# ifdef CONFIG_SCHED_USRWORK
-# define NWORKERS 1
-# define USRWORK 0
-# endif
-#else
+#if defined(CONFIG_SCHED_USRWORK) && !defined(__KERNEL__)
+/* User mode */
- /* In a flat build (CONFIG_BUILD_PROTECTED=n) or during the kernel phase of
- * the kernel build, there may be 0, 1, or 2 work queues.
- *
- * Work queue IDs (indices):
- *
- * Kernel Work Queues:
- * HPWORK: This ID of the high priority work queue that should only be
- * used for hi-priority, time-critical, driver bottom-half functions.
- *
- * LPWORK: This is the ID of the low priority work queue that can be
- * used for any purpose. if CONFIG_SCHED_LPWORK is not defined, then
- * there is only one kernel work queue and LPWORK == HPWORK.
- *
- * User Work Queue:
- * USRWORK: In the kernel phase a a kernel build, there should be no
- * references to user-space work queues. That would be an error.
- * Otherwise, in a flat build, user applications will use the lower
- * priority work queue (if there is one).
- */
+# define USRWORK 2 /* User mode work queue */
+# define HPWORK USRWORK /* Redirect kernel-mode references */
+# define LPWORK USRWORK
-# define HPWORK 0
+#else
+/* Kernel mode */
+
+# define HPWORK 0 /* High priority, kernel-mode work queue */
# ifdef CONFIG_SCHED_LPWORK
-# define LPWORK (HPWORK+1)
-# define NWORKERS 2
+# define LPWORK (HPWORK+1) /* Low priority, kernel-mode work queue */
# else
-# define LPWORK HPWORK
-# define NWORKERS 1
-# endif
-
-# if !defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_BUILD_KERNEL)
-# define USRWORK LPWORK
+# define LPWORK HPWORK /* Redirect low-priority references */
# endif
+# define USRWORK LPWORK /* Redirect user-mode references */
-#endif /* CONFIG_BUILD_PROTECTED && !__KERNEL__ */
+#endif /* CONFIG_SCHED_USRWORK && !__KERNEL__
/****************************************************************************
* Public Types
@@ -335,32 +320,6 @@ extern "C"
#define EXTERN extern
#endif
-/* The state of each work queue. This data structure is used internally by
- * the OS and worker queue logic and should not be accessed by application
- * logic.
- */
-
-#ifdef CONFIG_BUILD_PROTECTED
-
- /* Play some games in the kernel mode build to assure that different
- * naming is used for the global work queue data structures. This may
- * not be necessary but it safer.
- */
-
-# ifdef __KERNEL__
-EXTERN struct wqueue_s g_kernelwork[NWORKERS];
-# define g_work g_kernelwork
-# else
-EXTERN struct wqueue_s g_usrwork[NWORKERS];
-# define g_work g_usrwork
-# endif
-
-#else /* CONFIG_BUILD_PROTECTED */
-
-EXTERN struct wqueue_s g_work[NWORKERS];
-
-#endif /* CONFIG_BUILD_PROTECTED */
-
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@@ -427,7 +386,7 @@ int work_usrstart(void);
#endif
/****************************************************************************
- * Name: work_queue
+ * Name: work_queue and work_qqueue
*
* Description:
* Queue work to be performed at a later time. All queued work will be
@@ -440,6 +399,11 @@ int work_usrstart(void);
* from the queue, or (2) work_cancel() has been called to cancel the work
* and remove it from the work queue.
*
+ * work_queue() is the application interface. It simply maps the qid to
+ * the correct work queue and calls work_qqueue().
+ * work_qqueue() is the common cancellation logic that operates on the
+ * particular work queue selected by work_queue().
+ *
* Input parameters:
* qid - The work queue ID
* work - The work structure to queue
@@ -457,15 +421,22 @@ int work_usrstart(void);
int work_queue(int qid, FAR struct work_s *work, worker_t worker,
FAR void *arg, uint32_t delay);
+int work_qqueue(FAR struct wqueue_s *wqueue, FAR struct work_s *work,
+ worker_t worker, FAR void *arg, uint32_t delay);
/****************************************************************************
- * Name: work_cancel
+ * Name: work_cancel and work_qcancel;
*
* Description:
* Cancel previously queued work. This removes work from the work queue.
- * After work has been canceled, it may be re-queue by calling work_queue()
+ * After work has been cancelled, it may be re-queue by calling work_queue()
* again.
*
+ * work_cancel() is the application interface. It simply maps the qid to
+ * the correct work queue and calls work_qcancel().
+ * work_qcancel() is the common cancellation logic that operates on the
+ * particular work queue selected by work_cancel().
+ *
* Input parameters:
* qid - The work queue ID
* work - The previously queue work structure to cancel
@@ -473,8 +444,12 @@ int work_queue(int qid, FAR struct work_s *work, worker_t worker,
* Returned Value:
* Zero on success, a negated errno on failure
*
+ * -ENOENT - There is no such work queued.
+ * -EINVAL - An invalid work queue was specified
+ *
****************************************************************************/
+int work_qcancel(FAR struct wqueue_s *wqueue, FAR struct work_s *work);
int work_cancel(int qid, FAR struct work_s *work);
/****************************************************************************