mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
User-mode work queue logic should not disable interrupts
This commit is contained in:
@@ -40,8 +40,12 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <queue.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
|
||||
#include "wqueue/wqueue.h"
|
||||
@@ -68,6 +72,63 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: work_qqueue
|
||||
*
|
||||
* Description:
|
||||
* Queue 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
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int work_qqueue(FAR struct wqueue_s *wqueue, FAR struct work_s *work,
|
||||
worker_t worker, FAR void *arg, uint32_t delay)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
DEBUGASSERT(work != NULL);
|
||||
|
||||
/* First, initialize the work structure */
|
||||
|
||||
work->worker = worker; /* Work callback */
|
||||
work->arg = arg; /* Callback argument */
|
||||
work->delay = delay; /* Delay until work performed */
|
||||
|
||||
/* Now, time-tag that entry and put it in the work queue. This must be
|
||||
* done with interrupts disabled. This permits this function to be called
|
||||
* from with task logic or interrupt handlers.
|
||||
*/
|
||||
|
||||
flags = irqsave();
|
||||
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 */
|
||||
|
||||
irqrestore(flags);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user