From d648f9c8b488cc80e3994d080106545a98a24aa9 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 10 Dec 2016 16:34:14 -0600
Subject: [PATCH] Add task_testcancel()
---
Documentation/NuttxUserGuide.html | 130 +++++++++++-------
TODO | 11 +-
include/sched.h | 1 +
include/sys/syscall.h | 13 +-
libc/pthread/Make.defs | 3 -
libc/pthread/pthread_testcancel.c | 4 +
libc/sched/Make.defs | 2 +-
libc/sched/task_testcancel.c | 58 ++++++++
sched/pthread/Make.defs | 4 -
sched/task/Make.defs | 2 +-
.../task_testcancel.c} | 14 +-
syscall/syscall.csv | 2 +-
syscall/syscall_lookup.h | 4 +-
syscall/syscall_stublookup.c | 3 +-
14 files changed, 168 insertions(+), 83 deletions(-)
create mode 100644 libc/sched/task_testcancel.c
rename sched/{pthread/pthread_testcancel.c => task/task_testcancel.c} (89%)
diff --git a/Documentation/NuttxUserGuide.html b/Documentation/NuttxUserGuide.html
index a3a911b919..4a98bf50e4 100644
--- a/Documentation/NuttxUserGuide.html
+++ b/Documentation/NuttxUserGuide.html
@@ -205,50 +205,51 @@ paragraphs.
2.1.5 task_restart
2.1.6 task_setcancelstate
2.1.7 task_setcanceltype
+ 2.1.8 task_testcancel
Standard interfaces
Standard vfork and exec[v|l] interfaces:
Standard posix_spawn interfaces:
Non-standard task control interfaces inspired by posix_spawn:
@@ -647,7 +648,7 @@ No thread could be found corresponding to that specified by the given thread ID.
Assumptions/Limitations:
-POSIX Compatibility: This is a non-standard interface. It extends the functionality of pthread_setcancelstate() to tasks and supports use of task_delete.
+POSIX Compatibility: This is a non-standard interface. It extends the functionality of pthread_setcancelstate() to tasks and supports use of task_delete().
@@ -690,10 +691,38 @@ No thread could be found corresponding to that specified by the given thread ID.
-POSIX Compatibility: This is a non-standard interface. It extends the functionality of pthread_setcanceltype() to tasks and supports use of task_delete.
+POSIX Compatibility: This is a non-standard interface. It extends the functionality of pthread_setcanceltype() to tasks and supports use of task_delete().
-
+
+
+Function Prototype:
+
+
+
+ #include <sched.h>
+ void task_testcancel(void);
+
+
+
+Description:
+
+
+The task_testcancel() function creates a cancellation point in the calling task.
+The task_testcancel() function has no effect if cancelability is disabled.
+
+
+Input Parameters: None
+
+
+Returned Value: None
+
+
+POSIX Compatibility: This is a non-standard interface. It extends the functionality of pthread_testcancel() to tasks and supports use of task_delete().
+
+
+
+
Function Prototype:
@@ -739,7 +768,7 @@ And the UNIX interface:
The code parameter is ignored.
-
+
Function Prototype:
@@ -767,7 +796,7 @@ level.
Compatible with the POSIX interface of the same name.
-
+
Function Prototype:
@@ -801,7 +830,7 @@ pid_t vfork(void);
Compatible with the Unix interface of the same name.
-
+
Function Prototype:
@@ -887,7 +916,7 @@ int execv(FAR const char *path, FAR char *const argv[]);
There are, however, several compatibility issues as detailed in the description above.
-
+
Function Prototype:
@@ -931,7 +960,7 @@ int execl(FAR const char *path, ...);
There are, however, several compatibility issues as detailed in the description of execv().
-
+
Function Prototype:
@@ -1074,7 +1103,7 @@ int posix_spawnp(FAR pid_t *pid, FAR const char *file,
For the caller of posix_spawn(), the provided argv[0] will correspond to argv[1] received by the new task.
-
+
Function Prototype:
@@ -1100,7 +1129,7 @@ int posix_spawn_file_actions_init(FAR posix_spawn_file_actions_t *file_actions);
On success, this function returns 0; on failure it will return an error number from <errno.h>.
-
+
Function Prototype:
@@ -1127,7 +1156,7 @@ int posix_spawn_file_actions_destroy(FAR posix_spawn_file_actions_t *file_action
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1158,7 +1187,7 @@ int posix_spawn_file_actions_addclose(FAR posix_spawn_file_actions_t *file_actio
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1195,7 +1224,7 @@ int posix_spawn_file_actions_adddup2(FAR posix_spawn_file_actions_t *file_action
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1240,7 +1269,7 @@ int posix_spawn_file_actions_addopen(FAR posix_spawn_file_actions_t *file_action
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1276,7 +1305,7 @@ int posix_spawnattr_init(FAR posix_spawnattr_t *attr);
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1306,7 +1335,7 @@ int posix_spawnattr_getflags(FAR const posix_spawnattr_t *attr, FAR short *flags
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1336,7 +1365,7 @@ int posix_spawnattr_getschedparam(FAR const posix_spawnattr_t *attr, FAR struct
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1366,7 +1395,7 @@ int posix_spawnattr_getschedpolicy(FAR const posix_spawnattr_t *attr, FAR int *p
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1398,7 +1427,7 @@ int posix_spawnattr_getsigmask(FAR const posix_spawnattr_t *attr, FAR sigset_t *
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1428,7 +1457,7 @@ int posix_spawnattr_setflags(FAR posix_spawnattr_t *attr, short flags);
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1458,7 +1487,7 @@ int posix_spawnattr_setschedparam(FAR posix_spawnattr_t *attr, FAR const struct
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1488,7 +1517,7 @@ int posix_spawnattr_setschedpolicy(FAR posix_spawnattr_t *attr, int policy);
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1520,7 +1549,7 @@ int posix_spawnattr_setsigmask(FAR posix_spawnattr_t *attr, FAR const sigset_t *
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1634,7 +1663,7 @@ int task_spawn(FAR pid_t *pid, FAR const char *name, main_t entry,
This is a non-standard interface inspired by posix_spawn().
-
+
Function Prototype:
@@ -1664,7 +1693,7 @@ int task_spawnattr_getstacksize(FAR const posix_spawnattr_t *attr, FAR size_t *s
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -1694,7 +1723,7 @@ int task_spawnattr_setstacksize(FAR posix_spawnattr_t *attr, size_t stacksize);
On success, this function returns 0; on failure it will return an error number from <errno.h>
-
+
Function Prototype:
@@ -10370,6 +10399,7 @@ notify a task when a message is available on a queue.
task_spawnattr_getstacksize
task_spawnattr_setstacksize
Task Switching Interfaces
+ task_testcancel
telldir
timer_create
timer_delete
diff --git a/TODO b/TODO
index 263dce27e7..c208e56124 100644
--- a/TODO
+++ b/TODO
@@ -191,8 +191,15 @@ o Task/Scheduler (sched/)
does not do asynchronous deletion but should rather do the
same kind of synchronization such as the pthread cancellation
points. In this configuration, none of the issues above
- apply. It is only the asyncrhonous task deletion that cannot
- be supported.
+ apply. It is only the asynchronous task deletion that cannot
+ be supported. These helper functions are also available to
+ help manage task deletion:
+
+ int task_setcancelstate(int state, FAR int *oldstate);
+ int task_setcanceltype(int type, FAR int *oldtype);
+ void task_testcancel(void);
+
+ Which are analogous to the similarly named pthread_ interfaces.
Status: Open
Priority: Low and not easily removable.
diff --git a/include/sched.h b/include/sched.h
index f0e1195911..f63c42201a 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -243,6 +243,7 @@ int task_restart(pid_t pid);
int task_setcancelstate(int state, FAR int *oldstate);
int task_setcanceltype(int type, FAR int *oldtype);
+void task_testcancel(void);
/* Task Scheduling Interfaces (based on POSIX APIs) */
diff --git a/include/sys/syscall.h b/include/sys/syscall.h
index f0533b6289..8da2d8f968 100644
--- a/include/sys/syscall.h
+++ b/include/sys/syscall.h
@@ -132,8 +132,9 @@
# define SYS_up_assert (__SYS_task_delete+3)
# ifdef CONFIG_CANCELLATION_POINTS
-# define SYS_pthread_setcanceltype (__SYS_task_delete+4)
-# define __SYS_vfork (__SYS_task_delete+5)
+# define SYS_task_setcanceltype (__SYS_task_delete+4)
+# define SYS_task_testcancel (__SYS_task_delete+5)
+# define __SYS_vfork (__SYS_task_delete+6)
# else
# define __SYS_vfork (__SYS_task_delete+4)
# endif
@@ -411,13 +412,7 @@
# define SYS_pthread_setschedprio (__SYS_pthread+24)
# define SYS_pthread_setspecific (__SYS_pthread+25)
# define SYS_pthread_yield (__SYS_pthread+26)
-
-# ifdef CONFIG_CANCELLATION_POINTS
-# define SYS_pthread_testcancel (__SYS_pthread+27)
-# define __SYS_pthread_smp (__SYS_pthread+28)
-# else
-# define __SYS_pthread_smp (__SYS_pthread+27)
-# endif
+# define __SYS_pthread_smp (__SYS_pthread+27)
# ifdef CONFIG_SMP
# define SYS_pthread_setaffinity_np (__SYS_pthread_smp+0)
diff --git a/libc/pthread/Make.defs b/libc/pthread/Make.defs
index c530947fbc..f5eab2b943 100644
--- a/libc/pthread/Make.defs
+++ b/libc/pthread/Make.defs
@@ -48,10 +48,7 @@ CSRCS += pthread_mutexattr_getpshared.c pthread_mutexattr_setpshared.c
CSRCS += pthread_mutexattr_setprotocol.c pthread_mutexattr_getprotocol.c
CSRCS += pthread_mutexattr_settype.c pthread_mutexattr_gettype.c
CSRCS += pthread_setcancelstate.c pthread_setcanceltype.c
-
-ifneq ($(CONFIG_CANCELLATION_POINTS),y)
CSRCS += pthread_testcancel.c
-endif
ifeq ($(CONFIG_SMP),y)
CSRCS += pthread_attr_getaffinity.c pthread_attr_setaffinity.c
diff --git a/libc/pthread/pthread_testcancel.c b/libc/pthread/pthread_testcancel.c
index 99bc76a56e..c5bf14aec4 100644
--- a/libc/pthread/pthread_testcancel.c
+++ b/libc/pthread/pthread_testcancel.c
@@ -38,6 +38,7 @@
****************************************************************************/
#include
+#include
/****************************************************************************
* Public Functions
@@ -55,4 +56,7 @@
void pthread_testcancel(void)
{
+ /* task_testcancel() does the real work */
+
+ task_testcancel();
}
diff --git a/libc/sched/Make.defs b/libc/sched/Make.defs
index b7402aea05..5d875d3eac 100644
--- a/libc/sched/Make.defs
+++ b/libc/sched/Make.defs
@@ -38,7 +38,7 @@
CSRCS += sched_getprioritymax.c sched_getprioritymin.c
ifneq ($(CONFIG_CANCELLATION_POINTS),y)
-CSRCS += task_setcanceltype.c
+CSRCS += task_setcanceltype.c task_testcancel.c
endif
ifeq ($(CONFIG_SMP),y)
diff --git a/libc/sched/task_testcancel.c b/libc/sched/task_testcancel.c
new file mode 100644
index 0000000000..0d99dbebbc
--- /dev/null
+++ b/libc/sched/task_testcancel.c
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * libc/sched/task_testcancel.c
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: task_testcancel
+ *
+ * Description:
+ * The task_testcancel() function creates a cancellation point in the
+ * calling thread. The task_testcancel() function has no effect if
+ * cancelability is disabled
+ *
+ ****************************************************************************/
+
+void task_testcancel(void)
+{
+}
diff --git a/sched/pthread/Make.defs b/sched/pthread/Make.defs
index 1970de7804..6156dd5411 100644
--- a/sched/pthread/Make.defs
+++ b/sched/pthread/Make.defs
@@ -52,10 +52,6 @@ ifneq ($(CONFIG_DISABLE_SIGNALS),y)
CSRCS += pthread_condtimedwait.c pthread_kill.c pthread_sigmask.c
endif
-ifeq ($(CONFIG_CANCELLATION_POINTS),y)
-CSRCS += pthread_testcancel.c
-endif
-
ifeq ($(CONFIG_SMP),y)
CSRCS += pthread_setaffinity.c pthread_getaffinity.c
endif
diff --git a/sched/task/Make.defs b/sched/task/Make.defs
index b2543fccdd..a5c2295692 100644
--- a/sched/task/Make.defs
+++ b/sched/task/Make.defs
@@ -50,7 +50,7 @@ CSRCS += task_spawn.c
endif
ifeq ($(CONFIG_CANCELLATION_POINTS),y)
-CSRCS += task_setcanceltype.c
+CSRCS += task_setcanceltype.c task_testcancel.c
endif
ifneq ($(CONFIG_BINFMT_DISABLE),y)
diff --git a/sched/pthread/pthread_testcancel.c b/sched/task/task_testcancel.c
similarity index 89%
rename from sched/pthread/pthread_testcancel.c
rename to sched/task/task_testcancel.c
index d93af13807..b0407173e3 100644
--- a/sched/pthread/pthread_testcancel.c
+++ b/sched/task/task_testcancel.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * sched/pthread/pthread_testcancel.c
+ * sched/task/task_testcancel.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
@@ -39,28 +39,28 @@
#include
-#include
+#include
#include
#include
-#include "sched/sched.h"
+#include "task/task.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
- * Name: pthread_testcancel
+ * Name: task_testcancel
*
* Description:
- * The pthread_testcancel() function creates a cancellation point in the
- * calling thread. The pthread_testcancel() function has no effect if
+ * The task_testcancel() function creates a cancellation point in the
+ * calling thread. The task_testcancel() function has no effect if
* cancelability is disabled
*
****************************************************************************/
-void pthread_testcancel(void)
+void task_testcancel(void)
{
(void)enter_cancellation_point();
leave_cancellation_point();
diff --git a/syscall/syscall.csv b/syscall/syscall.csv
index 42706b701f..4dbcc98227 100644
--- a/syscall/syscall.csv
+++ b/syscall/syscall.csv
@@ -93,7 +93,6 @@
"pthread_setschedprio","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","int"
"pthread_setspecific","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_key_t","FAR const void*"
"pthread_sigmask","pthread.h","!defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD)","int","int","FAR const sigset_t*","FAR sigset_t*"
-"pthread_testcancel","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_CANCELLATION_POINTS)","void"
"pthread_yield","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","void"
"putenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char*"
"read","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","ssize_t","int","FAR void*","size_t"
@@ -152,6 +151,7 @@
"task_restart","sched.h","","int","pid_t"
"task_setcancelstate","sched.h","","int","int","FAR int*"
"task_setcanceltype","sched.h","defined(CONFIG_CANCELLATION_POINTS)","int","int","FAR int*"
+"task_testcancel","pthread.h","defined(CONFIG_CANCELLATION_POINTS)","void"
"telldir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","off_t","FAR DIR*"
"timer_create","time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","clockid_t","FAR struct sigevent*","FAR timer_t*"
"timer_delete","time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","timer_t"
diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h
index abd056fe37..25807590d8 100644
--- a/syscall/syscall_lookup.h
+++ b/syscall/syscall_lookup.h
@@ -91,6 +91,7 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
# ifdef CONFIG_CANCELLATION_POINTS
SYSCALL_LOOKUP(task_setcanceltype, 2, STUB_task_setcanceltype)
+ SYSCALL_LOOKUP(task_testcancel, 0, STUB_task_testcancel)
# endif
/* The following can be individually enabled */
@@ -299,9 +300,6 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
SYSCALL_LOOKUP(pthread_setschedprio, 2, STUB_pthread_setschedprio)
SYSCALL_LOOKUP(pthread_setspecific, 2, STUB_pthread_setspecific)
SYSCALL_LOOKUP(pthread_yield, 0, STUB_pthread_yield)
-# ifdef CONFIG_CANCELLATION_POINTS
- SYSCALL_LOOKUP(pthread_testcancel, 0, STUB_pthread_testcancel)
-# endif
# ifdef CONFIG_SMP
SYSCALL_LOOKUP(pthread_setaffinity, 3, STUB_pthread_setaffinity)
SYSCALL_LOOKUP(pthread_getaffinity, 3, STUB_pthread_getaffinity)
diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c
index 61ccb8ecd6..fda336d5aa 100644
--- a/syscall/syscall_stublookup.c
+++ b/syscall/syscall_stublookup.c
@@ -102,6 +102,7 @@ uintptr_t STUB_up_assert(int nbr, uintptr_t parm1, uintptr_t parm2);
uintptr_t STUB_task_setcanceltype(int nbr, uintptr_t parm1,
uintptr_t parm2);
+uintptr_t STUB_task_testcancel(int nbr);
/* The following can be individually enabled */
@@ -303,8 +304,6 @@ uintptr_t STUB_pthread_setspecific(int nbr, uintptr_t parm1,
uintptr_t parm2);
uintptr_t STUB_pthread_yield(int nbr);
-uintptr_t STUB_pthread_testcancel(int nbr);
-
uintptr_t STUB_pthread_setaffinity(int nbr, uintptr_t parm1,
uintptr_t parm2, uintptr_t parm3);
uintptr_t STUB_pthread_getaffinity(int nbr, uintptr_t parm1,