2009-11-05 22:44:33 +01:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/wqueue/work_cancel.c
|
2009-11-05 22:44:33 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2009-11-05 22:44:33 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-11-05 22:44:33 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2009-11-05 22:44:33 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <queue.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
|
2014-10-10 16:35:58 +02:00
|
|
|
#include "wqueue/wqueue.h"
|
|
|
|
|
2014-10-11 23:59:40 +02:00
|
|
|
#if defined(CONFIG_LIB_USRWORK) && !defined(__KERNEL__)
|
2009-11-05 22:44:33 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-10-10 16:35:58 +02:00
|
|
|
* Name: work_qcancel
|
2009-11-05 22:44:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2009-11-06 14:42:49 +01:00
|
|
|
* Cancel previously queued work. This removes work from the work queue.
|
2021-03-02 14:33:27 +01:00
|
|
|
* After work has been cancelled, it may be re-queue by calling
|
|
|
|
* work_queue() again.
|
2009-11-05 22:44:33 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2012-09-04 02:54:09 +02:00
|
|
|
* qid - The work queue ID
|
2009-11-05 22:44:33 +01:00
|
|
|
* work - The previously queue work structure to cancel
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2014-10-05 16:22:39 +02:00
|
|
|
* Zero (OK) on success, a negated errno on failure. This error may be
|
|
|
|
* reported:
|
|
|
|
*
|
|
|
|
* -ENOENT - There is no such work queued.
|
2014-10-10 16:35:58 +02:00
|
|
|
* -EINVAL - An invalid work queue was specified
|
2009-11-05 22:44:33 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-02 14:33:27 +01:00
|
|
|
static int work_qcancel(FAR struct usr_wqueue_s *wqueue,
|
|
|
|
FAR struct work_s *work)
|
2009-11-05 22:44:33 +01:00
|
|
|
{
|
2014-10-05 16:22:39 +02:00
|
|
|
int ret = -ENOENT;
|
2009-11-05 22:44:33 +01:00
|
|
|
|
2014-10-10 16:35:58 +02:00
|
|
|
DEBUGASSERT(work != NULL);
|
2009-11-05 22:44:33 +01:00
|
|
|
|
2014-10-10 22:52:04 +02:00
|
|
|
/* Get exclusive access to the work queue */
|
|
|
|
|
|
|
|
while (work_lock() < 0);
|
|
|
|
|
2009-11-05 22:44:33 +01:00
|
|
|
/* Cancelling the work is simply a matter of removing the work structure
|
|
|
|
* from the work queue. This must be done with interrupts disabled because
|
|
|
|
* new work is typically added to the work queue from interrupt handlers.
|
|
|
|
*/
|
|
|
|
|
2010-05-26 14:34:59 +02:00
|
|
|
if (work->worker != NULL)
|
|
|
|
{
|
2012-09-02 15:37:28 +02:00
|
|
|
/* A little test of the integrity of the work queue */
|
|
|
|
|
2015-09-30 22:03:55 +02:00
|
|
|
DEBUGASSERT(work->dq.flink != NULL ||
|
|
|
|
(FAR dq_entry_t *)work == wqueue->q.tail);
|
2015-10-12 15:45:02 +02:00
|
|
|
DEBUGASSERT(work->dq.blink != NULL ||
|
2015-09-30 22:03:55 +02:00
|
|
|
(FAR dq_entry_t *)work == wqueue->q.head);
|
2010-05-26 14:34:59 +02:00
|
|
|
|
2012-09-02 15:37:28 +02:00
|
|
|
/* Remove the entry from the work queue and make sure that it is
|
2015-09-30 22:03:55 +02:00
|
|
|
* marked as available (i.e., the worker field is nullified).
|
2012-09-02 15:37:28 +02:00
|
|
|
*/
|
|
|
|
|
2012-09-04 02:54:09 +02:00
|
|
|
dq_rem((FAR dq_entry_t *)work, &wqueue->q);
|
2010-05-26 14:34:59 +02:00
|
|
|
work->worker = NULL;
|
2014-10-05 16:22:39 +02:00
|
|
|
ret = OK;
|
2010-05-26 14:34:59 +02:00
|
|
|
}
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2014-10-10 22:52:04 +02:00
|
|
|
work_unlock();
|
2014-10-05 16:22:39 +02:00
|
|
|
return ret;
|
2009-11-05 22:44:33 +01:00
|
|
|
}
|
2012-09-04 02:54:09 +02:00
|
|
|
|
2014-10-10 22:52:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-10-10 16:35:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* 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.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2014-10-10 16:35:58 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int work_cancel(int qid, FAR struct work_s *work)
|
|
|
|
{
|
|
|
|
if (qid == USRWORK)
|
|
|
|
{
|
|
|
|
return work_qcancel(&g_usrwork, work);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-11 23:59:40 +02:00
|
|
|
#endif /* CONFIG_LIB_USRWORK && !__KERNEL__ */
|