2014-10-10 14:22:51 +02:00
|
|
|
/****************************************************************************
|
2014-10-10 16:35:58 +02:00
|
|
|
* sched/wqueue/kwork_cancel.c
|
2014-10-10 14:22:51 +02:00
|
|
|
*
|
2020-03-11 21:23:38 +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
|
2014-10-10 14:22:51 +02:00
|
|
|
*
|
2020-03-11 21:23:38 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-10-10 14:22:51 +02:00
|
|
|
*
|
2020-03-11 21:23:38 +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.
|
2014-10-10 14:22:51 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2014-10-10 22:52:04 +02:00
|
|
|
#include <assert.h>
|
2014-10-10 16:35:58 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
#include <nuttx/irq.h>
|
2014-10-10 22:52:04 +02:00
|
|
|
#include <nuttx/arch.h>
|
2022-09-25 17:08:38 +02:00
|
|
|
#include <nuttx/queue.h>
|
2014-10-10 14:22:51 +02:00
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
|
|
|
|
#include "wqueue/wqueue.h"
|
|
|
|
|
2014-10-10 16:35:58 +02:00
|
|
|
#ifdef CONFIG_SCHED_WORKQUEUE
|
2014-10-10 14:22:51 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-10-10 22:52:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: work_qcancel
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Cancel previously queued work. This removes work from the work queue.
|
2021-07-05 23:19:30 +02:00
|
|
|
* After work has been cancelled, it may be requeued by calling
|
2020-03-11 21:23:38 +01:00
|
|
|
* work_queue() again.
|
2014-10-10 22:52:04 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2014-10-10 22:52:04 +02:00
|
|
|
* qid - The work queue ID
|
2021-07-05 23:19:30 +02:00
|
|
|
* work - The previously queued work structure to cancel
|
2014-10-10 22:52:04 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success, a negated errno on failure. This error may be
|
|
|
|
* reported:
|
|
|
|
*
|
|
|
|
* -ENOENT - There is no such work queued.
|
|
|
|
* -EINVAL - An invalid work queue was specified
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-10-11 00:24:50 +02:00
|
|
|
static int work_qcancel(FAR struct kwork_wqueue_s *wqueue,
|
|
|
|
FAR struct work_s *work)
|
2014-10-10 22:52:04 +02:00
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
int ret = -ENOENT;
|
|
|
|
|
|
|
|
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
|
|
|
|
* new work is typically added to the work queue from interrupt handlers.
|
|
|
|
*/
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2014-10-10 22:52:04 +02:00
|
|
|
if (work->worker != NULL)
|
|
|
|
{
|
|
|
|
/* 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).
|
2014-10-10 22:52:04 +02:00
|
|
|
*/
|
|
|
|
|
2021-06-19 11:29:30 +02:00
|
|
|
if (WDOG_ISACTIVE(&work->u.timer))
|
|
|
|
{
|
|
|
|
wd_cancel(&work->u.timer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-17 09:55:03 +02:00
|
|
|
dq_rem((FAR dq_entry_t *)work, &wqueue->q);
|
2021-06-19 11:29:30 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 22:52:04 +02:00
|
|
|
work->worker = NULL;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2014-10-10 22:52:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-10 14:22:51 +02:00
|
|
|
/****************************************************************************
|
2014-10-10 16:35:58 +02:00
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: work_cancel
|
2014-10-10 14:22:51 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2014-10-10 16:35:58 +02:00
|
|
|
* Cancel previously queued user-mode work. This removes work from the
|
2021-07-05 23:19:30 +02:00
|
|
|
* user mode work queue. After work has been cancelled, it may be
|
|
|
|
* requeued by calling work_queue() again.
|
2014-10-10 14:22:51 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2014-10-10 16:47:41 +02:00
|
|
|
* qid - The work queue ID (must be HPWORK or LPWORK)
|
2021-07-05 23:19:30 +02:00
|
|
|
* work - The previously queued work structure to cancel
|
2014-10-10 14:22:51 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2014-10-10 16:35:58 +02:00
|
|
|
* Zero (OK) on success, a negated errno on failure. This error may be
|
|
|
|
* reported:
|
|
|
|
*
|
|
|
|
* -ENOENT - There is no such work queued.
|
|
|
|
* -EINVAL - An invalid work queue was specified
|
2014-10-10 14:22:51 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-10-10 16:35:58 +02:00
|
|
|
int work_cancel(int qid, FAR struct work_s *work)
|
2014-10-10 14:22:51 +02:00
|
|
|
{
|
2014-10-10 16:35:58 +02:00
|
|
|
#ifdef CONFIG_SCHED_HPWORK
|
|
|
|
if (qid == HPWORK)
|
2014-10-10 14:22:51 +02:00
|
|
|
{
|
2014-10-10 16:35:58 +02:00
|
|
|
/* Cancel high priority work */
|
2014-10-10 14:22:51 +02:00
|
|
|
|
2014-10-11 00:24:50 +02:00
|
|
|
return work_qcancel((FAR struct kwork_wqueue_s *)&g_hpwork, work);
|
2014-10-10 14:22:51 +02:00
|
|
|
}
|
2014-10-10 16:35:58 +02:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_LPWORK
|
|
|
|
if (qid == LPWORK)
|
|
|
|
{
|
|
|
|
/* Cancel low priority work */
|
2014-10-10 14:22:51 +02:00
|
|
|
|
2014-10-11 00:24:50 +02:00
|
|
|
return work_qcancel((FAR struct kwork_wqueue_s *)&g_lpwork, work);
|
2014-10-10 16:35:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-10-10 14:22:51 +02:00
|
|
|
}
|
|
|
|
|
2014-10-10 16:35:58 +02:00
|
|
|
#endif /* CONFIG_SCHED_WORKQUEUE */
|