This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 82f46144b064f940b62a9f5a62b13572a0252200
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Oct 20 21:02:48 2026 +0200

    libs/libc/sched: Report the cancel type that applies without cancel points.
    
    Without CONFIG_CANCELLATION_POINTS, pthread_cancel() acts at once, and
    pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED) fails with EINVAL, but
    the old type that pthread_setcanceltype() returned was
    PTHREAD_CANCEL_DEFERRED.  A program could not see that a cancellation
    can stop the thread at any point, also with a mutex held.
    
    Return PTHREAD_CANCEL_ASYNCHRONOUS as the old type in this
    configuration.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 libs/libc/sched/task_setcanceltype.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/libs/libc/sched/task_setcanceltype.c 
b/libs/libc/sched/task_setcanceltype.c
index d748e6e02fb..c2798d3be3f 100644
--- a/libs/libc/sched/task_setcanceltype.c
+++ b/libs/libc/sched/task_setcanceltype.c
@@ -50,7 +50,9 @@
  *   TASK_CANCEL_ASYNCHRONOUS.
  *
  *   The cancellability state and type of any newly created tasks are
- *   TASK_CANCEL_ENABLE and TASK_CANCEL_DEFERRED respectively.
+ *   TASK_CANCEL_ENABLE and TASK_CANCEL_DEFERRED respectively.  Without
+ *   CONFIG_CANCELLATION_POINTS, the type is always TASK_CANCEL_ASYNCHRONOUS
+ *   and TASK_CANCEL_DEFERRED fails with EINVAL.
  *
  ****************************************************************************/
 
@@ -63,6 +65,7 @@ int task_setcanceltype(int type, FAR int *oldtype)
 
   if (oldtype != NULL)
     {
+#ifdef CONFIG_CANCELLATION_POINTS
       if ((tls->tl_cpstate & CANCEL_FLAG_CANCEL_ASYNC) != 0u)
         {
           *oldtype = TASK_CANCEL_ASYNCHRONOUS;
@@ -71,6 +74,11 @@ int task_setcanceltype(int type, FAR int *oldtype)
         {
           *oldtype = TASK_CANCEL_DEFERRED;
         }
+#else
+      /* Without cancellation points, every cancellation acts at once */
+
+      *oldtype = TASK_CANCEL_ASYNCHRONOUS;
+#endif
     }
 
   /* Set the new cancellation type */

Reply via email to