2016-12-09 15:13:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* sched/task/task_cancelpt.c
|
|
|
|
*
|
2021-02-08 16:33:58 +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
|
2016-12-09 15:13:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-12-09 15:13:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +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.
|
2016-12-09 15:13:28 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Cancellation Points.
|
|
|
|
*
|
|
|
|
* Cancellation points shall occur when a thread is executing the following
|
|
|
|
* functions:
|
|
|
|
*
|
|
|
|
* accept() mq_timedsend() putpmsg() sigtimedwait()
|
|
|
|
* aio_suspend() msgrcv() pwrite() sigwait()
|
|
|
|
* clock_nanosleep() msgsnd() read() sigwaitinfo()
|
|
|
|
* close() msync() readv() sleep()
|
|
|
|
* connect() nanosleep() recv() system()
|
|
|
|
* creat() open() recvfrom() tcdrain()
|
|
|
|
* fcntl() pause() recvmsg() usleep()
|
|
|
|
* fdatasync() poll() select() wait()
|
|
|
|
* fsync() pread() sem_timedwait() waitid()
|
|
|
|
* getmsg() pselect() sem_wait() waitpid()
|
|
|
|
* getpmsg() pthread_cond_timedwait() send() write()
|
|
|
|
* lockf() pthread_cond_wait() sendmsg() writev()
|
|
|
|
* mq_receive() pthread_join() sendto()
|
|
|
|
* mq_send() pthread_testcancel() sigpause()
|
|
|
|
* mq_timedreceive() putmsg() sigsuspend()
|
|
|
|
*
|
|
|
|
* Each of the above function must call enter_cancellation_point() on entry
|
2020-03-08 13:51:33 +01:00
|
|
|
* in order to establish the cancellation point and
|
|
|
|
* leave_cancellation_point() on exit. These functions are described below.
|
2016-12-09 15:13:28 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sched.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2016-12-09 16:44:23 +01:00
|
|
|
#include <errno.h>
|
2016-12-09 15:13:28 +01:00
|
|
|
|
2016-12-09 16:44:23 +01:00
|
|
|
#include <nuttx/irq.h>
|
2016-12-10 16:08:26 +01:00
|
|
|
#include <nuttx/cancelpt.h>
|
2021-05-08 12:20:02 +02:00
|
|
|
#include <nuttx/pthread.h>
|
2016-12-09 15:13:28 +01:00
|
|
|
|
2016-12-09 16:44:23 +01:00
|
|
|
#include "sched/sched.h"
|
|
|
|
#include "semaphore/semaphore.h"
|
2017-10-12 16:55:19 +02:00
|
|
|
#include "signal/signal.h"
|
2016-12-09 16:44:23 +01:00
|
|
|
#include "mqueue/mqueue.h"
|
2016-12-09 15:13:28 +01:00
|
|
|
#include "task/task.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_CANCELLATION_POINTS
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: enter_cancellation_point
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Called at the beginning of the cancellation point to establish the
|
|
|
|
* cancellation point. This function does the following:
|
|
|
|
*
|
|
|
|
* 1. If deferred cancellation does not apply to this thread, nothing is
|
|
|
|
* done, otherwise, it
|
|
|
|
* 2. Sets state information in the caller's TCB and increments a nesting
|
|
|
|
* count.
|
|
|
|
* 3. If this is the outermost nesting level, it checks if there is a
|
|
|
|
* pending cancellation and, if so, calls either exit() or
|
2016-12-09 16:44:23 +01:00
|
|
|
* pthread_exit(), depending upon the type of the thread.
|
2016-12-09 15:13:28 +01:00
|
|
|
*
|
2016-12-10 15:36:58 +01:00
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2016-12-10 15:36:58 +01:00
|
|
|
* true is returned if a cancellation is pending but cannot be performed
|
|
|
|
* now due to the nesting level.
|
|
|
|
*
|
2016-12-09 15:13:28 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2016-12-10 15:36:58 +01:00
|
|
|
bool enter_cancellation_point(void)
|
2016-12-09 15:13:28 +01:00
|
|
|
{
|
2016-12-09 16:44:23 +01:00
|
|
|
FAR struct tcb_s *tcb = this_task();
|
2016-12-10 15:36:58 +01:00
|
|
|
bool ret = false;
|
2016-12-09 16:44:23 +01:00
|
|
|
|
|
|
|
/* Disabling pre-emption should provide sufficient protection. We only
|
|
|
|
* need the TCB to be stationary (no interrupt level modification is
|
|
|
|
* anticipated).
|
2016-12-09 19:01:18 +01:00
|
|
|
*
|
2020-02-22 19:31:14 +01:00
|
|
|
* REVISIT: is locking the scheduler sufficient in SMP mode?
|
2016-12-09 16:44:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
|
|
|
|
/* If cancellation is disabled on this thread or if this thread is using
|
|
|
|
* asynchronous cancellation, then do nothing.
|
|
|
|
*
|
|
|
|
* Special case: if the cpcount count is greater than zero, then we are
|
|
|
|
* nested and the above condition was certainly true at the outermost
|
|
|
|
* nesting level.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (((tcb->flags & TCB_FLAG_NONCANCELABLE) == 0 &&
|
|
|
|
(tcb->flags & TCB_FLAG_CANCEL_DEFERRED) != 0) ||
|
2017-08-15 01:19:27 +02:00
|
|
|
tcb->cpcount > 0)
|
2016-12-09 16:44:23 +01:00
|
|
|
{
|
2016-12-10 15:36:58 +01:00
|
|
|
/* Check if there is a pending cancellation */
|
2016-12-09 16:44:23 +01:00
|
|
|
|
2016-12-10 15:36:58 +01:00
|
|
|
if ((tcb->flags & TCB_FLAG_CANCEL_PENDING) != 0)
|
2016-12-09 16:44:23 +01:00
|
|
|
{
|
2016-12-10 15:36:58 +01:00
|
|
|
/* Yes... return true (if we don't exit here) */
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
/* If there is a pending cancellation and we are at the outermost
|
|
|
|
* nesting level of cancellation function calls, then exit
|
|
|
|
* according to the type of the thread.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tcb->cpcount == 0)
|
|
|
|
{
|
2016-12-09 16:44:23 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2020-03-08 13:51:33 +01:00
|
|
|
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) ==
|
|
|
|
TCB_FLAG_TTYPE_PTHREAD)
|
2017-08-15 01:19:27 +02:00
|
|
|
{
|
2021-05-08 12:20:02 +02:00
|
|
|
tcb->flags &= ~TCB_FLAG_CANCEL_PENDING;
|
|
|
|
tcb->flags |= TCB_FLAG_CANCEL_DOING;
|
2021-05-17 11:31:13 +02:00
|
|
|
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
|
2021-05-08 12:20:02 +02:00
|
|
|
up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit,
|
|
|
|
PTHREAD_CANCELED);
|
|
|
|
#else
|
2017-08-15 01:19:27 +02:00
|
|
|
pthread_exit(PTHREAD_CANCELED);
|
2021-05-08 12:20:02 +02:00
|
|
|
#endif
|
2017-08-15 01:19:27 +02:00
|
|
|
}
|
|
|
|
else
|
2016-12-09 16:44:23 +01:00
|
|
|
#endif
|
2017-08-15 01:19:27 +02:00
|
|
|
{
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2016-12-10 15:36:58 +01:00
|
|
|
}
|
2016-12-09 16:44:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, indicate that we are at a cancellation point by
|
|
|
|
* incrementing the nesting level of the cancellation point
|
|
|
|
* functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(tcb->cpcount < INT16_MAX);
|
|
|
|
tcb->cpcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sched_unlock();
|
2016-12-10 15:36:58 +01:00
|
|
|
return ret;
|
2016-12-09 15:13:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-12-09 16:44:23 +01:00
|
|
|
* Name: leave_cancellation_point
|
2016-12-09 15:13:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Called at the end of the cancellation point. This function does the
|
|
|
|
* following:
|
|
|
|
*
|
|
|
|
* 1. If deferred cancellation does not apply to this thread, nothing is
|
|
|
|
* done, otherwise, it
|
|
|
|
* 2. Clears state information in the caller's TCB and decrements a
|
|
|
|
* nesting count.
|
|
|
|
* 3. If this is the outermost nesting level, it checks if there is a
|
|
|
|
* pending cancellation and, if so, calls either exit() or
|
2016-12-09 16:44:23 +01:00
|
|
|
* pthread_exit(), depending upon the type of the thread.
|
2016-12-09 15:13:28 +01:00
|
|
|
*
|
2016-12-10 15:36:58 +01:00
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2016-12-10 15:36:58 +01:00
|
|
|
* None
|
|
|
|
*
|
2016-12-09 15:13:28 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2016-12-09 16:44:23 +01:00
|
|
|
void leave_cancellation_point(void)
|
2016-12-09 15:13:28 +01:00
|
|
|
{
|
2016-12-09 16:44:23 +01:00
|
|
|
FAR struct tcb_s *tcb = this_task();
|
|
|
|
|
|
|
|
/* Disabling pre-emption should provide sufficient protection. We only
|
|
|
|
* need the TCB to be stationary (no interrupt level modification is
|
|
|
|
* anticipated).
|
2016-12-09 19:01:18 +01:00
|
|
|
*
|
2020-02-22 19:31:14 +01:00
|
|
|
* REVISIT: is locking the scheduler sufficient in SMP mode?
|
2016-12-09 16:44:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
|
|
|
|
/* If cancellation is disabled on this thread or if this thread is using
|
|
|
|
* asynchronous cancellation, then do nothing. Here we check only the
|
|
|
|
* nesting level: if the cpcount count is greater than zero, then the
|
|
|
|
* required condition was certainly true at the outermost nesting level.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tcb->cpcount > 0)
|
|
|
|
{
|
|
|
|
/* Decrement the nesting level. If if would decrement to zero, then
|
|
|
|
* we are at the outermost nesting level and may need to do more.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tcb->cpcount == 1)
|
|
|
|
{
|
|
|
|
/* We are no longer at the cancellation point */
|
|
|
|
|
|
|
|
tcb->cpcount = 0;
|
|
|
|
|
|
|
|
/* If there is a pending cancellation then just exit according to
|
|
|
|
* the type of the thread.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((tcb->flags & TCB_FLAG_CANCEL_PENDING) != 0)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2020-03-08 13:51:33 +01:00
|
|
|
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) ==
|
|
|
|
TCB_FLAG_TTYPE_PTHREAD)
|
2017-08-15 01:19:27 +02:00
|
|
|
{
|
2021-05-08 12:20:02 +02:00
|
|
|
tcb->flags &= ~TCB_FLAG_CANCEL_PENDING;
|
|
|
|
tcb->flags |= TCB_FLAG_CANCEL_DOING;
|
2021-05-17 11:31:13 +02:00
|
|
|
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
|
2021-05-08 12:20:02 +02:00
|
|
|
up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit,
|
|
|
|
PTHREAD_CANCELED);
|
|
|
|
#else
|
2017-08-15 01:19:27 +02:00
|
|
|
pthread_exit(PTHREAD_CANCELED);
|
2021-05-08 12:20:02 +02:00
|
|
|
#endif
|
2017-08-15 01:19:27 +02:00
|
|
|
}
|
|
|
|
else
|
2016-12-09 16:44:23 +01:00
|
|
|
#endif
|
2017-08-15 01:19:27 +02:00
|
|
|
{
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2016-12-09 16:44:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-15 01:19:27 +02:00
|
|
|
/* We are not at the outermost nesting level. Just decrment the
|
|
|
|
* nesting level count.
|
|
|
|
*/
|
2016-12-09 16:44:23 +01:00
|
|
|
|
|
|
|
tcb->cpcount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sched_unlock();
|
2016-12-09 15:13:28 +01:00
|
|
|
}
|
|
|
|
|
2017-10-09 17:43:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: check_cancellation_point
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Returns true if:
|
|
|
|
*
|
|
|
|
* 1. Deferred cancellation does applies to this thread,
|
|
|
|
* 2. We are within a cancellation point (i.e., the nesting level in the
|
|
|
|
* TCB is greater than zero).
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-10-09 17:43:04 +02:00
|
|
|
* true is returned if a cancellation is pending but cannot be performed
|
|
|
|
* now due to the nesting level.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool check_cancellation_point(void)
|
|
|
|
{
|
|
|
|
FAR struct tcb_s *tcb = this_task();
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
/* Disabling pre-emption should provide sufficient protection. We only
|
|
|
|
* need the TCB to be stationary (no interrupt level modification is
|
|
|
|
* anticipated).
|
|
|
|
*
|
2020-02-22 19:31:14 +01:00
|
|
|
* REVISIT: is locking the scheduler sufficient in SMP mode?
|
2017-10-09 17:43:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
|
|
|
|
/* If cancellation is disabled on this thread or if this thread is using
|
|
|
|
* asynchronous cancellation, then return false.
|
|
|
|
*
|
|
|
|
* If the cpcount count is greater than zero, then we within a
|
|
|
|
* cancellation and will true if there is a pending cancellation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (((tcb->flags & TCB_FLAG_NONCANCELABLE) == 0 &&
|
|
|
|
(tcb->flags & TCB_FLAG_CANCEL_DEFERRED) != 0) ||
|
|
|
|
tcb->cpcount > 0)
|
|
|
|
{
|
|
|
|
/* Check if there is a pending cancellation. If so, return true. */
|
|
|
|
|
|
|
|
ret = ((tcb->flags & TCB_FLAG_CANCEL_PENDING) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sched_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-06 18:41:47 +02:00
|
|
|
#endif /* CONFIG_CANCELLATION_POINTS */
|
|
|
|
|
2016-12-09 15:13:28 +01:00
|
|
|
/****************************************************************************
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* Name: nxnotify_cancellation
|
2016-12-09 15:13:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Called by task_delete() or pthread_cancel() if the cancellation occurs
|
|
|
|
* while we the thread is within the cancellation point. This logic
|
|
|
|
* behaves much like sending a signal: It will cause waiting threads
|
|
|
|
* to wake up and terminated with ECANCELED. A call to
|
2020-02-23 09:50:23 +01:00
|
|
|
* leave_cancellation_point() would then follow, causing the thread to
|
2016-12-09 15:13:28 +01:00
|
|
|
* exit.
|
|
|
|
*
|
2020-06-06 18:41:47 +02:00
|
|
|
* Returned Value:
|
|
|
|
* Indicate whether the notification delivery to the target
|
|
|
|
*
|
2016-12-09 15:13:28 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2020-06-06 18:41:47 +02:00
|
|
|
bool nxnotify_cancellation(FAR struct tcb_s *tcb)
|
2016-12-09 15:13:28 +01:00
|
|
|
{
|
2016-12-09 16:44:23 +01:00
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* We need perform the following operations from within a critical section
|
|
|
|
* because it can compete with interrupt level activity.
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
/* We only notify the cancellation if (1) the thread has not disabled
|
2020-02-23 09:50:23 +01:00
|
|
|
* cancellation, (2) the thread uses the deferred cancellation mode,
|
2016-12-09 16:44:23 +01:00
|
|
|
* (3) the thread is waiting within a cancellation point.
|
|
|
|
*/
|
|
|
|
|
2020-06-06 18:41:47 +02:00
|
|
|
/* Check to see if this task has the non-cancelable bit set. */
|
|
|
|
|
|
|
|
if ((tcb->flags & TCB_FLAG_NONCANCELABLE) != 0)
|
2016-12-09 16:44:23 +01:00
|
|
|
{
|
2020-06-06 18:41:47 +02:00
|
|
|
/* Then we cannot cancel the thread now. Here is how this is
|
|
|
|
* supposed to work:
|
|
|
|
*
|
|
|
|
* "When cancellability is disabled, all cancels are held pending
|
|
|
|
* in the target thread until the thread changes the cancellability.
|
|
|
|
* When cancellability is deferred, all cancels are held pending in
|
|
|
|
* the target thread until the thread changes the cancellability,
|
|
|
|
* calls a function which is a cancellation point or calls
|
|
|
|
* pthread_testcancel(), thus creating a cancellation point. When
|
|
|
|
* cancellability is asynchronous, all cancels are acted upon
|
|
|
|
* immediately, interrupting the thread with its processing."
|
2016-12-09 16:44:23 +01:00
|
|
|
*/
|
|
|
|
|
2020-06-06 18:41:47 +02:00
|
|
|
tcb->flags |= TCB_FLAG_CANCEL_PENDING;
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_CANCELLATION_POINTS
|
|
|
|
/* Check if this task supports deferred cancellation */
|
2016-12-09 16:44:23 +01:00
|
|
|
|
2020-06-06 18:41:47 +02:00
|
|
|
if ((tcb->flags & TCB_FLAG_CANCEL_DEFERRED) != 0)
|
|
|
|
{
|
|
|
|
/* Then we cannot cancel the task asynchronously.
|
|
|
|
* Mark the cancellation as pending.
|
2016-12-09 16:44:23 +01:00
|
|
|
*/
|
|
|
|
|
2020-06-06 18:41:47 +02:00
|
|
|
tcb->flags |= TCB_FLAG_CANCEL_PENDING;
|
2017-10-12 16:55:19 +02:00
|
|
|
|
2020-06-06 18:41:47 +02:00
|
|
|
/* If the task is waiting at a cancellation point, then notify of the
|
|
|
|
* cancellation thereby waking the task up with an ECANCELED error.
|
2017-10-12 16:55:19 +02:00
|
|
|
*/
|
|
|
|
|
2020-06-06 18:41:47 +02:00
|
|
|
if (tcb->cpcount > 0)
|
2016-12-09 16:44:23 +01:00
|
|
|
{
|
2020-06-06 18:41:47 +02:00
|
|
|
/* If the thread is blocked waiting for a semaphore, then the
|
|
|
|
* thread must be unblocked to handle the cancellation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tcb->task_state == TSTATE_WAIT_SEM)
|
|
|
|
{
|
|
|
|
nxsem_wait_irq(tcb, ECANCELED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the thread is blocked waiting on a signal, then the
|
|
|
|
* thread must be unblocked to handle the cancellation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
else if (tcb->task_state == TSTATE_WAIT_SIG)
|
|
|
|
{
|
|
|
|
nxsig_wait_irq(tcb, ECANCELED);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
|
|
|
/* If the thread is blocked waiting on a message queue, then
|
|
|
|
* the thread must be unblocked to handle the cancellation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
else if (tcb->task_state == TSTATE_WAIT_MQNOTEMPTY ||
|
|
|
|
tcb->task_state == TSTATE_WAIT_MQNOTFULL)
|
|
|
|
{
|
|
|
|
nxmq_wait_irq(tcb, ECANCELED);
|
|
|
|
}
|
2016-12-09 16:44:23 +01:00
|
|
|
#endif
|
2020-06-06 18:41:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return true;
|
2016-12-09 16:44:23 +01:00
|
|
|
}
|
2020-06-06 18:41:47 +02:00
|
|
|
#endif
|
2016-12-09 16:44:23 +01:00
|
|
|
|
|
|
|
leave_critical_section(flags);
|
2020-06-06 18:41:47 +02:00
|
|
|
return false;
|
2016-12-09 15:13:28 +01:00
|
|
|
}
|