summaryrefslogtreecommitdiff
path: root/nuttx/include/nuttx/wqueue.h
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-03-05 18:57:51 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-03-05 18:57:51 +0000
commit7b06c73d1d766cd3376be29dccbd28a16e3f385b (patch)
tree20b00664065816849ca8f29e46281759085270ba /nuttx/include/nuttx/wqueue.h
parenteb573ac290c8f1a6bcb0816c8552ca88278cda11 (diff)
downloadnuttx-7b06c73d1d766cd3376be29dccbd28a16e3f385b.tar.gz
nuttx-7b06c73d1d766cd3376be29dccbd28a16e3f385b.tar.bz2
nuttx-7b06c73d1d766cd3376be29dccbd28a16e3f385b.zip
Move work queue logic from sched/ to libc/wqueue. It is not core logic and will be extended to support user-space work queues
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5711 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/include/nuttx/wqueue.h')
-rw-r--r--nuttx/include/nuttx/wqueue.h78
1 files changed, 67 insertions, 11 deletions
diff --git a/nuttx/include/nuttx/wqueue.h b/nuttx/include/nuttx/wqueue.h
index d56901d89..67a518008 100644
--- a/nuttx/include/nuttx/wqueue.h
+++ b/nuttx/include/nuttx/wqueue.h
@@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/wqueue.h
*
- * Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -83,6 +83,10 @@
* priority worker thread. Default: CONFIG_IDLETHREAD_STACKSIZE.
*/
+#if defined(CONFIG_SCHED_WORKQUEUE) && defined(CONFIG_DISABLE_SIGNALS)
+# warning "Worker thread support requires signals"
+#endif
+
#ifndef CONFIG_SCHED_WORKPRIORITY
# define CONFIG_SCHED_WORKPRIORITY 192
#endif
@@ -109,6 +113,14 @@
# endif
#endif
+/* How many worker threads are there? */
+
+#ifdef CONFIG_SCHED_LPWORK
+# define NWORKERS 2
+#else
+# define NWORKERS 1
+#endif
+
/* Work queue IDs (indices):
*
* Kernel Work Queues:
@@ -144,6 +156,17 @@
#ifndef __ASSEMBLY__
+/* This structure defines the state on one work queue. This structure is
+ * used internally by the OS and worker queue logic and should not be
+ * accessed by application logic.
+ */
+
+struct wqueue_s
+{
+ pid_t pid; /* The task ID of the worker thread */
+ struct dq_queue_s q; /* The queue of pending work */
+};
+
/* Defines the work callback */
typedef void (*worker_t)(FAR void *arg);
@@ -155,11 +178,11 @@ typedef void (*worker_t)(FAR void *arg);
struct work_s
{
- struct dq_entry_s dq; /* Implements a doubly linked list */
- worker_t worker; /* Work callback */
- FAR void *arg; /* Callback argument */
- uint32_t qtime; /* Time work queued */
- uint32_t delay; /* Delay until work performed */
+ struct dq_entry_s dq; /* Implements a doubly linked list */
+ worker_t worker; /* Work callback */
+ FAR void *arg; /* Callback argument */
+ uint32_t qtime; /* Time work queued */
+ uint32_t delay; /* Delay until work performed */
};
/****************************************************************************
@@ -168,16 +191,49 @@ struct work_s
#ifdef __cplusplus
#define EXTERN extern "C"
-extern "C" {
+extern "C"
+{
#else
#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.
+ */
+
+EXTERN struct wqueue_s g_work[NWORKERS];
+
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
+ * Name: work_hpthread and work_lpthread
+ *
+ * Description:
+ * These are the main worker threads that performs actions placed on the
+ * work lists. One thread also performs periodic garbage collection (that
+ * is performed by the idle thread if CONFIG_SCHED_WORKQUEUE is not defined).
+ *
+ * These entrypoints are referenced by OS internally and should not be
+ * accessed by application logic.
+ *
+ * Input parameters:
+ * argc, argv (not used)
+ *
+ * Returned Value:
+ * Does not return
+ *
+ ****************************************************************************/
+
+int work_hpthread(int argc, char *argv[]);
+
+#ifdef CONFIG_SCHED_LPWORK
+int work_lpthread(int argc, char *argv[]);
+#endif
+
+/****************************************************************************
* Name: work_queue
*
* Description:
@@ -206,8 +262,8 @@ extern "C" {
*
****************************************************************************/
-EXTERN int work_queue(int qid, FAR struct work_s *work, worker_t worker,
- FAR void *arg, uint32_t delay);
+int work_queue(int qid, FAR struct work_s *work, worker_t worker,
+ FAR void *arg, uint32_t delay);
/****************************************************************************
* Name: work_cancel
@@ -226,7 +282,7 @@ EXTERN int work_queue(int qid, FAR struct work_s *work, worker_t worker,
*
****************************************************************************/
-EXTERN int work_cancel(int qid, FAR struct work_s *work);
+int work_cancel(int qid, FAR struct work_s *work);
/****************************************************************************
* Name: work_signal
@@ -244,7 +300,7 @@ EXTERN int work_cancel(int qid, FAR struct work_s *work);
*
****************************************************************************/
-EXTERN int work_signal(int qid);
+int work_signal(int qid);
/****************************************************************************
* Name: work_available