mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
Decoupling work queue data structures. This is part of the preparation to support multiple low-priority worker threads
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* libc/wqueue/work_cancel.c
|
||||
*
|
||||
* Copyright (C) 2009-2010, 2012-2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009-2010, 2012-2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -42,11 +42,12 @@
|
||||
#include <queue.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
|
||||
#include "wqueue/wqueue.h"
|
||||
|
||||
#ifdef CONFIG_SCHED_WORKQUEUE
|
||||
|
||||
/****************************************************************************
|
||||
@@ -74,7 +75,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: work_cancel
|
||||
* Name: work_qcancel
|
||||
*
|
||||
* Description:
|
||||
* Cancel previously queued work. This removes work from the work queue.
|
||||
@@ -90,16 +91,16 @@
|
||||
* reported:
|
||||
*
|
||||
* -ENOENT - There is no such work queued.
|
||||
* -EINVAL - An invalid work queue was specified
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int work_cancel(int qid, FAR struct work_s *work)
|
||||
int work_qcancel(FAR struct wqueue_s *wqueue, FAR struct work_s *work)
|
||||
{
|
||||
FAR struct wqueue_s *wqueue = &g_work[qid];
|
||||
irqstate_t flags;
|
||||
int ret = -ENOENT;
|
||||
|
||||
DEBUGASSERT(work != NULL && (unsigned)qid < NWORKERS);
|
||||
DEBUGASSERT(work != NULL);
|
||||
|
||||
/* Cancelling the work is simply a matter of removing the work structure
|
||||
* from the work queue. This must be done with interrupts disabled because
|
||||
@@ -115,7 +116,7 @@ int work_cancel(int qid, FAR struct work_s *work)
|
||||
DEBUGASSERT(work->dq.blink || (FAR dq_entry_t *)work == wqueue->q.head);
|
||||
|
||||
/* Remove the entry from the work queue and make sure that it is
|
||||
* mark as availalbe (i.e., the worker field is nullified).
|
||||
* mark as available (i.e., the worker field is nullified).
|
||||
*/
|
||||
|
||||
dq_rem((FAR dq_entry_t *)work, &wqueue->q);
|
||||
@@ -127,4 +128,39 @@ int work_cancel(int qid, FAR struct work_s *work)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: work_cancel
|
||||
*
|
||||
* Description:
|
||||
* Cancel previously queued user-mode work. This removes work from the
|
||||
* user mode work queue. After work has been cancelled, it may be re-queue
|
||||
* by calling work_queue() again.
|
||||
*
|
||||
* Input parameters:
|
||||
* qid - The work queue ID (must be USRWORK)
|
||||
* work - The previously queue work structure to cancel
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success, a negated errno on failure. This error may be
|
||||
* reported:
|
||||
*
|
||||
* -ENOENT - There is no such work queued.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_SCHED_USRWORK) && !defined(__KERNEL__)
|
||||
|
||||
int work_cancel(int qid, FAR struct work_s *work)
|
||||
{
|
||||
if (qid == USRWORK)
|
||||
{
|
||||
return work_qcancel(&g_usrwork, work);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SCHED_USRWORK && !__KERNEL__ */
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE */
|
||||
|
||||
@@ -62,30 +62,6 @@
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* The state of each work queue. */
|
||||
|
||||
#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.
|
||||
*
|
||||
* In this case g_work is #define'd to be either g_kernelwork or
|
||||
* g_usrwork in include/nuttx/wqueue.h
|
||||
*/
|
||||
|
||||
# ifdef __KERNEL__
|
||||
struct wqueue_s g_kernelwork[NWORKERS];
|
||||
# else
|
||||
struct wqueue_s g_usrwork[NWORKERS];
|
||||
# endif
|
||||
|
||||
#else /* CONFIG_BUILD_PROTECTED */
|
||||
|
||||
struct wqueue_s g_work[NWORKERS];
|
||||
|
||||
#endif /* CONFIG_BUILD_PROTECTED */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* libc/wqueue/work_queue.c
|
||||
*
|
||||
* Copyright (C) 2009-2011, 2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009-2011, 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -43,12 +43,13 @@
|
||||
#include <queue.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
|
||||
#include "wqueue/wqueue.h"
|
||||
|
||||
#ifdef CONFIG_SCHED_WORKQUEUE
|
||||
|
||||
/****************************************************************************
|
||||
@@ -76,7 +77,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: work_queue
|
||||
* Name: work_qqueue
|
||||
*
|
||||
* Description:
|
||||
* Queue work to be performed at a later time. All queued work will be
|
||||
@@ -104,13 +105,12 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
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)
|
||||
{
|
||||
FAR struct wqueue_s *wqueue = &g_work[qid];
|
||||
irqstate_t flags;
|
||||
|
||||
DEBUGASSERT(work != NULL && (unsigned)qid < NWORKERS);
|
||||
DEBUGASSERT(work != NULL);
|
||||
|
||||
/* First, initialize the work structure */
|
||||
|
||||
@@ -133,4 +133,49 @@ int work_queue(int qid, FAR struct work_s *work, worker_t worker,
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: work_queue
|
||||
*
|
||||
* Description:
|
||||
* Queue user-mode work to be performed at a later time. All queued work
|
||||
* will be performed on the worker thread of of execution (not the caller's).
|
||||
*
|
||||
* The work structure is allocated by caller, but completely managed by
|
||||
* the work queue logic. The caller should never modify the contents of
|
||||
* the work queue structure; the caller should not call work_queue()
|
||||
* again until either (1) the previous work has been performed and removed
|
||||
* from the queue, or (2) work_cancel() has been called to cancel the work
|
||||
* and remove it from the work queue.
|
||||
*
|
||||
* Input parameters:
|
||||
* qid - The work queue ID (index)
|
||||
* work - The work structure to queue
|
||||
* worker - The worker callback to be invoked. The callback will invoked
|
||||
* on the worker thread of execution.
|
||||
* arg - The argument that will be passed to the workder callback when
|
||||
* int is invoked.
|
||||
* delay - Delay (in clock ticks) from the time queue until the worker
|
||||
* is invoked. Zero means to perform the work immediately.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success, a negated errno on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_SCHED_USRWORK) && !defined(__KERNEL__)
|
||||
|
||||
int work_queue(int qid, FAR struct work_s *work, worker_t worker,
|
||||
FAR void *arg, uint32_t delay)
|
||||
{
|
||||
if (qid == USRWORK)
|
||||
{
|
||||
return work_qqueue(&g_usrwork, work, worker, arg, delay);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SCHED_USRWORK && !__KERNEL__ */
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* libc/wqueue/work_signal.c
|
||||
*
|
||||
* Copyright (C) 2009-2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009-2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,10 +40,11 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/wqueue.h>
|
||||
|
||||
#include "wqueue/wqueue.h"
|
||||
|
||||
#ifdef CONFIG_SCHED_WORKQUEUE
|
||||
|
||||
/****************************************************************************
|
||||
@@ -85,10 +86,28 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_SCHED_USRWORK) && !defined(__KERNEL__)
|
||||
|
||||
int work_signal(int qid)
|
||||
{
|
||||
DEBUGASSERT((unsigned)qid < NWORKERS);
|
||||
return kill(g_work[qid].pid, SIGWORK);
|
||||
int ret;
|
||||
|
||||
if (qid == USRWORK)
|
||||
{
|
||||
/* Signal the worker thread */
|
||||
|
||||
ret = kill(g_usrwork.pid, SIGWORK);
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
return -errcode;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SCHED_USRWORK && !__KERNEL__ */
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE */
|
||||
|
||||
@@ -48,6 +48,10 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The state of the user mode work queue. */
|
||||
|
||||
extern struct wqueue_s g_usrwork;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
@@ -93,7 +97,7 @@ int work_usrthread(int argc, char *argv[])
|
||||
* we process items in the work list.
|
||||
*/
|
||||
|
||||
work_process(&g_work[USRWORK]);
|
||||
work_process(&g_usrwork);
|
||||
}
|
||||
|
||||
return OK; /* To keep some compilers happy */
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/****************************************************************************
|
||||
* sched/libc/wqueue.h
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __LIBC_WQUEUE_WQUEUE_H
|
||||
#define __LIBC_WQUEUE_WQUEUE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_SCHED_WORKQUEUE
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_SCHED_USRWORK) && !defined(__KERNEL__)
|
||||
|
||||
/* The state of the user mode work queue */
|
||||
|
||||
extern struct wqueue_s g_usrwork;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE */
|
||||
#endif /* __LIBC_WQUEUE_WQUEUE_H */
|
||||
Reference in New Issue
Block a user