From 9780f68188ae4466d6d57d307fc31766b811a988 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 10 Oct 2014 16:24:50 -0600 Subject: Add support for multiple low-priority worker threads --- nuttx/libc/wqueue/work_cancel.c | 2 +- nuttx/libc/wqueue/work_queue.c | 7 ++++--- nuttx/libc/wqueue/work_signal.c | 2 +- nuttx/libc/wqueue/work_usrthread.c | 24 ++++++++++++------------ nuttx/libc/wqueue/wqueue.h | 11 ++++++++++- 5 files changed, 28 insertions(+), 18 deletions(-) (limited to 'nuttx/libc') diff --git a/nuttx/libc/wqueue/work_cancel.c b/nuttx/libc/wqueue/work_cancel.c index fa04f6ca9..322a85ae7 100644 --- a/nuttx/libc/wqueue/work_cancel.c +++ b/nuttx/libc/wqueue/work_cancel.c @@ -92,7 +92,7 @@ * ****************************************************************************/ -static int work_qcancel(FAR struct wqueue_s *wqueue, FAR struct work_s *work) +static int work_qcancel(FAR struct usr_wqueue_s *wqueue, FAR struct work_s *work) { int ret = -ENOENT; diff --git a/nuttx/libc/wqueue/work_queue.c b/nuttx/libc/wqueue/work_queue.c index a17d8d14b..19e441178 100644 --- a/nuttx/libc/wqueue/work_queue.c +++ b/nuttx/libc/wqueue/work_queue.c @@ -102,8 +102,9 @@ * ****************************************************************************/ -static int work_qqueue(FAR struct wqueue_s *wqueue, FAR struct work_s *work, - worker_t worker, FAR void *arg, uint32_t delay) +static int work_qqueue(FAR struct usr_wqueue_s *wqueue, + FAR struct work_s *work, worker_t worker, + FAR void *arg, uint32_t delay) { DEBUGASSERT(work != NULL); @@ -122,7 +123,7 @@ static int work_qqueue(FAR struct wqueue_s *wqueue, FAR struct work_s *work, work->qtime = clock_systimer(); /* Time work queued */ dq_addlast((FAR dq_entry_t *)work, &wqueue->q); - kill(wqueue->pid[0], SIGWORK); /* Wake up the worker thread */ + kill(wqueue->pid, SIGWORK); /* Wake up the worker thread */ work_unlock(); return OK; diff --git a/nuttx/libc/wqueue/work_signal.c b/nuttx/libc/wqueue/work_signal.c index 813b9e8d6..1ab861dfe 100644 --- a/nuttx/libc/wqueue/work_signal.c +++ b/nuttx/libc/wqueue/work_signal.c @@ -97,7 +97,7 @@ int work_signal(int qid) { /* Signal the worker thread */ - ret = kill(g_usrwork.pid[0], SIGWORK); + ret = kill(g_usrwork.pid, SIGWORK); if (ret < 0) { int errcode = errno; diff --git a/nuttx/libc/wqueue/work_usrthread.c b/nuttx/libc/wqueue/work_usrthread.c index 0b4606e2e..48ccf1f8b 100644 --- a/nuttx/libc/wqueue/work_usrthread.c +++ b/nuttx/libc/wqueue/work_usrthread.c @@ -83,7 +83,7 @@ /* The state of the user mode work queue. */ -struct wqueue_s g_usrwork; +struct usr_wqueue_s g_usrwork; /* This semaphore supports exclusive access to the user-mode work queue */ @@ -118,7 +118,7 @@ extern pthread_mutex_t g_usrmutex; * ****************************************************************************/ -void work_process(FAR struct wqueue_s *wqueue) +void work_process(FAR struct usr_wqueue_s *wqueue) { volatile FAR struct work_s *work; worker_t worker; @@ -351,21 +351,21 @@ int work_usrstart(void) /* Start a user-mode worker thread for use by applications. */ - g_usrwork.pid[0] = task_create("uwork", - CONFIG_SCHED_USRWORKPRIORITY, - CONFIG_SCHED_USRWORKSTACKSIZE, - (main_t)work_usrthread, - (FAR char * const *)NULL); + g_usrwork.pid = task_create("uwork", + CONFIG_SCHED_USRWORKPRIORITY, + CONFIG_SCHED_USRWORKSTACKSIZE, + (main_t)work_usrthread, + (FAR char * const *)NULL); - DEBUGASSERT(g_usrwork.pid[0] > 0); - if (g_usrwork.pid[0] < 0) + DEBUGASSERT(g_usrwork.pid > 0); + if (g_usrwork.pid < 0) { int errcode = errno; DEBUGASSERT(errcode > 0); return -errcode; } - return g_usrwork.pid[0]; + return g_usrwork.pid; } #else { @@ -398,8 +398,8 @@ int work_usrstart(void) (void)pthread_detach(usrwork); - g_usrwork.pid[0] = (pid_t)usrwork; - return g_usrwork.pid[0]; + g_usrwork.pid = (pid_t)usrwork; + return g_usrwork.pid; } #endif } diff --git a/nuttx/libc/wqueue/wqueue.h b/nuttx/libc/wqueue/wqueue.h index 9fcbabdb8..13bfacf0a 100644 --- a/nuttx/libc/wqueue/wqueue.h +++ b/nuttx/libc/wqueue/wqueue.h @@ -57,6 +57,15 @@ * Public Type Definitions ****************************************************************************/ +/* This structure defines the state of one user-modework queue. */ + +struct usr_wqueue_s +{ + uint32_t delay; /* Delay between polling cycles (ticks) */ + struct dq_queue_s q; /* The queue of pending work */ + pid_t pid; /* The task ID of the worker thread(s) */ +}; + /**************************************************************************** * Public Data ****************************************************************************/ @@ -64,7 +73,7 @@ #if defined(CONFIG_SCHED_USRWORK) && !defined(__KERNEL__) /* The state of the user mode work queue */ -extern struct wqueue_s g_usrwork; +extern struct usr_wqueue_s g_usrwork; /* This semaphore/mutex supports exclusive access to the user-mode work queue */ -- cgit v1.2.3