Add task_setcanceltype()

This commit is contained in:
Gregory Nutt 2016-12-10 16:06:14 -06:00
parent 5fb207eb36
commit f132960789
13 changed files with 211 additions and 102 deletions

View file

@ -204,50 +204,51 @@ paragraphs.
<li><a href="#taskdelete">2.1.4 task_delete</a></li>
<li><a href="#taskrestart">2.1.5 task_restart</a></li>
<li><a href="#tasksetcancelstate">2.1.6 task_setcancelstate</a></li>
<li><a href="#tasksetcanceltype">2.1.7 task_setcanceltype</a></li>
</ul>
<p>
Standard interfaces
</p>
<ul>
<li><a href="#exit">2.1.7 exit</a></li>
<li><a href="#getpid">2.1.8 getpid</a></li>
<li><a href="#exit">2.1.8 exit</a></li>
<li><a href="#getpid">2.1.9 getpid</a></li>
</ul>
<p>
Standard <code>vfork</code> and <code>exec[v|l]</code> interfaces:
</p>
<ul>
<li><a href="#vfork">2.1.9 vfork</a></li>
<li><a href="#execv">2.1.10 execv</a></li>
<li><a href="#execl">2.1.11 execl</a></li>
<li><a href="#vfork">2.1.10 vfork</a></li>
<li><a href="#execv">2.1.11 execv</a></li>
<li><a href="#execl">2.1.12 execl</a></li>
</ul>
<p>
Standard <code>posix_spawn</code> interfaces:
</p>
<ul>
<li><a href="#posix_spawn">2.1.12 posix_spawn and posix_spawnp</a></li>
<li><a href="#posix_spawn_file_actions_init">2.1.13 posix_spawn_file_actions_init</a></li>
<li><a href="#posix_spawn_file_actions_destroy">2.1.14 posix_spawn_file_actions_destroy</a></li>
<li><a href="#posix_spawn_file_actions_addclose">2.1.15 posix_spawn_file_actions_addclose</a></li>
<li><a href="#posix_spawn_file_actions_adddup2">2.1.16 posix_spawn_file_actions_adddup2</a></li>
<li><a href="#posix_spawn_file_actions_addopen">2.1.17 posix_spawn_file_actions_addopen</a></li>
<li><a href="#posix_spawnattr_init">2.1.18 posix_spawnattr_init</a></li>
<li><a href="#posix_spawnattr_getflags">2.1.19 posix_spawnattr_getflags</a></li>
<li><a href="#posix_spawnattr_getschedparam">2.1.20 posix_spawnattr_getschedparam</a></li>
<li><a href="#posix_spawnattr_getschedpolicy">2.1.21 posix_spawnattr_getschedpolicy</a></li>
<li><a href="#posix_spawnattr_getsigmask">2.1.22 posix_spawnattr_getsigmask</a></li>
<li><a href="#posix_spawnattr_setflags">2.1.23 posix_spawnattr_setflags</a></li>
<li><a href="#posix_spawnattr_setschedparam">2.1.24 posix_spawnattr_setschedparam</a></li>
<li><a href="#posix_spawnattr_setschedpolicy">2.1.25 posix_spawnattr_setschedpolicy</a></li>
<li><a href="#posix_spawnattr_setsigmask">2.1.26 posix_spawnattr_setsigmask</a></li>
<li><a href="#posix_spawn">2.1.13 posix_spawn and posix_spawnp</a></li>
<li><a href="#posix_spawn_file_actions_init">2.1.14 posix_spawn_file_actions_init</a></li>
<li><a href="#posix_spawn_file_actions_destroy">2.1.15 posix_spawn_file_actions_destroy</a></li>
<li><a href="#posix_spawn_file_actions_addclose">2.1.16 posix_spawn_file_actions_addclose</a></li>
<li><a href="#posix_spawn_file_actions_adddup2">2.1.17 posix_spawn_file_actions_adddup2</a></li>
<li><a href="#posix_spawn_file_actions_addopen">2.1.18 posix_spawn_file_actions_addopen</a></li>
<li><a href="#posix_spawnattr_init">2.1.19 posix_spawnattr_init</a></li>
<li><a href="#posix_spawnattr_getflags">2.1.20 posix_spawnattr_getflags</a></li>
<li><a href="#posix_spawnattr_getschedparam">2.1.21 posix_spawnattr_getschedparam</a></li>
<li><a href="#posix_spawnattr_getschedpolicy">2.1.22 posix_spawnattr_getschedpolicy</a></li>
<li><a href="#posix_spawnattr_getsigmask">2.1.23 posix_spawnattr_getsigmask</a></li>
<li><a href="#posix_spawnattr_setflags">2.1.24 posix_spawnattr_setflags</a></li>
<li><a href="#posix_spawnattr_setschedparam">2.1.25 posix_spawnattr_setschedparam</a></li>
<li><a href="#posix_spawnattr_setschedpolicy">2.1.26 posix_spawnattr_setschedpolicy</a></li>
<li><a href="#posix_spawnattr_setsigmask">2.1.27 posix_spawnattr_setsigmask</a></li>
</ul>
<p>
Non-standard task control interfaces inspired by <code>posix_spawn</code>:
</p>
<ul>
<li><a href="#task_spawn">2.1.27 task_spawn</a></li>
<li><a href="#task_spawnattr_getstacksize">2.1.28 task_spawnattr_getstacksize</a></li>
<li><a href="#task_spawnattr_setstacksize">2.1.29 task_spawnattr_setstacksize</a></li>
<li><a href="#posix_spawn_file_actions_init">2.1.30 posix_spawn_file_actions_init</a></li>
<li><a href="#task_spawn">2.1.28 task_spawn</a></li>
<li><a href="#task_spawnattr_getstacksize">2.1.29 task_spawnattr_getstacksize</a></li>
<li><a href="#task_spawnattr_setstacksize">2.1.30 task_spawnattr_setstacksize</a></li>
<li><a href="#posix_spawn_file_actions_init">2.1.31 posix_spawn_file_actions_init</a></li>
</ul>
<H3><a name="taskcreate">2.1.1 task_create</a></H3>
@ -609,8 +610,6 @@ VxWorks provides the following similar interface:
</pre>
<p>
<b>Description:</b>
</p>
<p>
The <code>task_setcancelstate()</code> function atomically
sets both the calling task's cancelability state to the indicated
state and returns the previous cancelability state at the location
@ -651,7 +650,50 @@ No thread could be found corresponding to that specified by the given thread ID.
<b>POSIX Compatibility:</b> This is a non-standard interface. It extends the functionality of <code>pthread_setcancelstate()</code> to tasks and supports use of <code>task_delete</code>.
</p>
<H3><a name="exit">2.1.7 exit</a></H3>
<H3><a name="tasksetcanceltype">2.1.7 task_setcanceltype</a></H3>
<p>
<b>Function Prototype:</b>
<p>
<pre>
#include &lt;sched.h&gt;
int task_setcanceltype(int type, FAR int *oldtype);
</pre>
<p>
<b>Description:</b>
The <code>task_setcanceltype()</code> function atomically both sets the calling task's cancelability type to the indicated type and returns the previous cancelability type at the location referenced by <code>oldtype</code>.
Legal values for type are <code>TASK_CANCEL_DEFERRED</code> and <code>TASK_CANCEL_ASYNCHRONOUS</code>.
</p>
<p>
The cancelability state and type of any newly created tasks are <code>TASK_CANCEL_ENABLE</code> and <code>TASK_CANCEL_DEFERRED</code> respectively.
</p>
<p>
<b>Input Parameters:</b>
</p>
<p>
<ul>
<li><code>type</code>
New cancellation state. One of <code>PTHREAD_CANCEL_DEFERRED</code> or <code>PTHREAD_CANCEL_ASYNCHRONOUS</code>.</li>
<li><code>oldtype</code>.
Location to return the previous cancellation type.
</ul>
</p>
<p>
<b>Returned Value:</b>
</p>
<p>
Zero (<code>OK</code>) on success; <code>ERROR</code> is returned on any failure with the <code>errno</code> value set appropriately:
</p>
<p>
<ul>
<li><code>ESRCH</code>.
No thread could be found corresponding to that specified by the given thread ID.</li>
</ul>
</p>
<p>
<b>POSIX Compatibility:</b> This is a non-standard interface. It extends the functionality of <code>pthread_setcanceltype()</code> to tasks and supports use of <code>task_delete</code>.
</p>
<H3><a name="exit">2.1.8 exit</a></H3>
<p>
<b>Function Prototype:</b>
@ -697,7 +739,7 @@ And the UNIX interface:
<li>The <code>code</code> parameter is ignored.
</ul>
<H3><a name="getpid">2.1.8 getpid</a></H3>
<H3><a name="getpid">2.1.9 getpid</a></H3>
<p>
<b>Function Prototype:</b>
@ -725,7 +767,7 @@ level.
Compatible with the POSIX interface of the same name.
</p>
<H3><a name="vfork">2.1.9 vfork</a></H3>
<H3><a name="vfork">2.1.10 vfork</a></H3>
<p>
<b>Function Prototype:</b>
</p>
@ -759,7 +801,7 @@ pid_t vfork(void);
Compatible with the Unix interface of the same name.
</p>
<H3><a name="execv">2.1.10 execv</a></H3>
<H3><a name="execv">2.1.11 execv</a></H3>
<p>
<b>Function Prototype:</b>
</p>
@ -845,7 +887,7 @@ int execv(FAR const char *path, FAR char *const argv[]);
There are, however, several compatibility issues as detailed in the description above.
</p>
<H3><a name="execl">2.1.11 execl</a></H3>
<H3><a name="execl">2.1.12 execl</a></H3>
<p>
<b>Function Prototype:</b>
</p>
@ -889,7 +931,7 @@ int execl(FAR const char *path, ...);
There are, however, several compatibility issues as detailed in the description of <a href="#execv">execv()</a>.
</p>
<h3><a name="posix_spawn">2.1.12 posix_spawn and posix_spawnp</a></h3>
<h3><a name="posix_spawn">2.1.13 posix_spawn and posix_spawnp</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1032,7 +1074,7 @@ int posix_spawnp(FAR pid_t *pid, FAR const char *file,
For the caller of <code>posix_spawn()</code>, the provided argv[0] will correspond to <code>argv[1]</code> received by the new task.
</p>
<h3><a name="posix_spawn_file_actions_init">2.1.13 posix_spawn_file_actions_init</a></h3>
<h3><a name="posix_spawn_file_actions_init">2.1.14 posix_spawn_file_actions_init</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1058,7 +1100,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 <code>&lt;errno.h&gt;</code>.
<p>
<h3><a name="posix_spawn_file_actions_destroy">2.1.14 posix_spawn_file_actions_destroy</a></h3>
<h3><a name="posix_spawn_file_actions_destroy">2.1.15 posix_spawn_file_actions_destroy</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1085,7 +1127,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 <code>&lt;errno.h&gt;</code>
<p>
<h3><a name="posix_spawn_file_actions_addclose">2.1.15 posix_spawn_file_actions_addclose</a></h3>
<h3><a name="posix_spawn_file_actions_addclose">2.1.16 posix_spawn_file_actions_addclose</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1116,7 +1158,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawn_file_actions_adddup2">2.1.16 posix_spawn_file_actions_adddup2</a></h3>
<h3><a name="posix_spawn_file_actions_adddup2">2.1.17 posix_spawn_file_actions_adddup2</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1153,7 +1195,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawn_file_actions_addopen">2.1.17 posix_spawn_file_actions_addopen</a></h3>
<h3><a name="posix_spawn_file_actions_addopen">2.1.18 posix_spawn_file_actions_addopen</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1198,7 +1240,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawnattr_init">2.1.18 posix_spawnattr_init</a></h3>
<h3><a name="posix_spawnattr_init">2.1.19 posix_spawnattr_init</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1234,7 +1276,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawnattr_getflags">2.1.19 posix_spawnattr_getflags</a></h3>
<h3><a name="posix_spawnattr_getflags">2.1.20 posix_spawnattr_getflags</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1264,7 +1306,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawnattr_getschedparam">2.1.20 posix_spawnattr_getschedparam</a></h3>
<h3><a name="posix_spawnattr_getschedparam">2.1.21 posix_spawnattr_getschedparam</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1294,7 +1336,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawnattr_getschedpolicy">2.1.21 posix_spawnattr_getschedpolicy</a></h3>
<h3><a name="posix_spawnattr_getschedpolicy">2.1.22 posix_spawnattr_getschedpolicy</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1324,7 +1366,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawnattr_getsigmask">2.1.22 posix_spawnattr_getsigmask</a></h3>
<h3><a name="posix_spawnattr_getsigmask">2.1.23 posix_spawnattr_getsigmask</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1356,7 +1398,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawnattr_setflags">2.1.23 posix_spawnattr_setflags</a></h3>
<h3><a name="posix_spawnattr_setflags">2.1.24 posix_spawnattr_setflags</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1386,7 +1428,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawnattr_setschedparam">2.1.24 posix_spawnattr_setschedparam</a></h3>
<h3><a name="posix_spawnattr_setschedparam">2.1.25 posix_spawnattr_setschedparam</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1416,7 +1458,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawnattr_setschedpolicy">2.1.25 posix_spawnattr_setschedpolicy</a></h3>
<h3><a name="posix_spawnattr_setschedpolicy">2.1.26 posix_spawnattr_setschedpolicy</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1446,7 +1488,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawnattr_setsigmask">2.1.26 posix_spawnattr_setsigmask</a></h3>
<h3><a name="posix_spawnattr_setsigmask">2.1.27 posix_spawnattr_setsigmask</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1478,7 +1520,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="task_spawn">2.1.27 task_spawn</a></h3>
<h3><a name="task_spawn">2.1.28 task_spawn</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1592,7 +1634,7 @@ int task_spawn(FAR pid_t *pid, FAR const char *name, main_t entry,
This is a non-standard interface inspired by <code>posix_spawn()</code>.
</p>
<h3><a name="task_spawnattr_getstacksize">2.1.28 task_spawnattr_getstacksize</a></h3>
<h3><a name="task_spawnattr_getstacksize">2.1.29 task_spawnattr_getstacksize</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1622,7 +1664,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="task_spawnattr_setstacksize">2.1.29 task_spawnattr_setstacksize</a></h3>
<h3><a name="task_spawnattr_setstacksize">2.1.30 task_spawnattr_setstacksize</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -1652,7 +1694,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 <code>&lt;errno.h&gt;</code>
</p>
<h3><a name="posix_spawn_file_actions_init">2.1.30 posix_spawn_file_actions_init</a></h3>
<h3><a name="posix_spawn_file_actions_init">2.1.31 posix_spawn_file_actions_init</a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -10323,6 +10365,7 @@ notify a task when a message is available on a queue.
<li><a href="#taskrestart">task_restart</a></li>
<li><a href="#Task_Schedule">Task Scheduling Interfaces</a>
<li><a href="#tasksetcancelstate">task_setcancelstate</a></li>
<li><a href="#tasksetcanceltype>task_setcanceltype</a></li>
<li><a href="#task_spawn">task_spawn</a></li>
<li><a href="#task_spawnattr_getstacksize">task_spawnattr_getstacksize</a></li>
<li><a href="#task_spawnattr_setstacksize">task_spawnattr_setstacksize</a></li>

View file

@ -54,18 +54,30 @@
/* POSIX-like scheduling policies */
#define SCHED_FIFO 1 /* FIFO priority scheduling policy */
#define SCHED_RR 2 /* Round robin scheduling policy */
#define SCHED_SPORADIC 3 /* Sporadic scheduling policy */
#define SCHED_OTHER 4 /* Not supported */
#define SCHED_FIFO 1 /* FIFO priority scheduling policy */
#define SCHED_RR 2 /* Round robin scheduling policy */
#define SCHED_SPORADIC 3 /* Sporadic scheduling policy */
#define SCHED_OTHER 4 /* Not supported */
/* Maximum number of SCHED_SPORADIC replenishments */
#define SS_REPL_MAX CONFIG_SCHED_SPORADIC_MAXREPL
#define SS_REPL_MAX CONFIG_SCHED_SPORADIC_MAXREPL
/* Cancellation definitions *****************************************************/
/* Cancellation states used by task_setcancelstate() */
#define TASK_CANCEL_ENABLE (0)
#define TASK_CANCEL_DISABLE (1)
/* Cancellation types used by task_setcanceltype() */
#define TASK_CANCEL_DEFERRED (0)
#define TASK_CANCEL_ASYNCHRONOUS (1)
/* Pthread definitions **********************************************************/
#define PTHREAD_KEYS_MAX CONFIG_NPTHREAD_KEYS
#define PTHREAD_KEYS_MAX CONFIG_NPTHREAD_KEYS
/* CPU affinity mask helpers ***************************************************/
/* These are not standard but are defined for Linux compatibility */
@ -230,6 +242,7 @@ int task_delete(pid_t pid);
int task_restart(pid_t pid);
int task_setcancelstate(int state, FAR int *oldstate);
int task_setcanceltype(int type, FAR int *oldtype);
/* Task Scheduling Interfaces (based on POSIX APIs) */

View file

@ -130,7 +130,13 @@
# define SYS_task_restart (__SYS_task_delete+1)
# define SYS_task_setcancelstate (__SYS_task_delete+2)
# define SYS_up_assert (__SYS_task_delete+3)
# define __SYS_vfork (__SYS_task_delete+4)
# ifdef CONFIG_CANCELLATION_POINTS
# define SYS_pthread_setcanceltype (__SYS_task_delete+4)
# define __SYS_vfork (__SYS_task_delete+5)
# else
# define __SYS_vfork (__SYS_task_delete+4)
# endif
/* The following can be individually enabled */
@ -407,9 +413,8 @@
# define SYS_pthread_yield (__SYS_pthread+26)
# ifdef CONFIG_CANCELLATION_POINTS
# define SYS_pthread_setcanceltype (__SYS_pthread+27)
# define SYS_pthread_testcancel (__SYS_pthread+28)
# define __SYS_pthread_smp (__SYS_pthread+29)
# define SYS_pthread_testcancel (__SYS_pthread+27)
# define __SYS_pthread_smp (__SYS_pthread+28)
# else
# define __SYS_pthread_smp (__SYS_pthread+27)
# endif

View file

@ -47,9 +47,10 @@ CSRCS += pthread_mutexattr_init.c pthread_mutexattr_destroy.c
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_setcanceltype.c pthread_testcancel.c
CSRCS += pthread_testcancel.c
endif
ifeq ($(CONFIG_SMP),y)

View file

@ -38,8 +38,24 @@
****************************************************************************/
#include <pthread.h>
#include <sched.h>
#include <errno.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* The following are defined in different header files but must have the
* same values.
*/
#if PTHREAD_CANCEL_DEFERRED != TASK_CANCEL_DEFERRED
# error We must have PTHREAD_CANCEL_DEFERRED == TASK_CANCEL_DEFERRED
#endif
#if PTHREAD_CANCEL_ASYNCHRONOUS != TASK_CANCEL_ASYNCHRONOUS
# error We must have PTHREAD_CANCEL_ASYNCHRONOUS == TASK_CANCEL_ASYNCHRONOUS
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -62,14 +78,15 @@
int pthread_setcanceltype(int type, FAR int *oldtype)
{
/* Return the current type if so requrested */
int ret;
if (oldtype != NULL)
/* task_setcanceltype() can do this */
ret = task_setcanceltype(type, oldtype);
if (ret < 0)
{
*oldtype = PTHREAD_CANCEL_ASYNCHRONOUS;
ret = errno;
}
/* Check the requested cancellation type */
return (type == PTHREAD_CANCEL_ASYNCHRONOUS) ? OK : ENOSYS;
return ret;
}

View file

@ -37,6 +37,10 @@
CSRCS += sched_getprioritymax.c sched_getprioritymin.c
ifneq ($(CONFIG_CANCELLATION_POINTS),y)
CSRCS += task_setcanceltype.c
endif
ifeq ($(CONFIG_SMP),y)
CSRCS += sched_cpucount.c
endif

View file

@ -53,7 +53,7 @@ CSRCS += pthread_condtimedwait.c pthread_kill.c pthread_sigmask.c
endif
ifeq ($(CONFIG_CANCELLATION_POINTS),y)
CSRCS += pthread_setcanceltype.c pthread_testcancel.c
CSRCS += pthread_testcancel.c
endif
ifeq ($(CONFIG_SMP),y)

View file

@ -49,6 +49,10 @@ ifneq ($(CONFIG_BUILD_KERNEL),y)
CSRCS += task_spawn.c
endif
ifeq ($(CONFIG_CANCELLATION_POINTS),y)
CSRCS += task_setcanceltype.c
endif
ifneq ($(CONFIG_BINFMT_DISABLE),y)
ifeq ($(CONFIG_LIBC_EXECFUNCS),y)
CSRCS += task_execv.c task_posixspawn.c

View file

@ -39,6 +39,9 @@
#include <nuttx/config.h>
#include <stdlib.h>
#include <pthread.h>
#include <sched.h>
#include <errno.h>
#include "sched/sched.h"
@ -88,17 +91,17 @@ int task_setcancelstate(int state, FAR int *oldstate)
{
if ((tcb->flags & TCB_FLAG_NONCANCELABLE) != 0)
{
*oldstate = PTHREAD_CANCEL_DISABLE;
*oldstate = TASK_CANCEL_DISABLE;
}
else
{
*oldstate = PTHREAD_CANCEL_ENABLE;
*oldstate = TASK_CANCEL_ENABLE;
}
}
/* Set the new cancellation state */
if (state == PTHREAD_CANCEL_ENABLE)
if (state == TASK_CANCEL_ENABLE)
{
/* Clear the non-cancelable flag */
@ -124,27 +127,27 @@ int task_setcancelstate(int state, FAR int *oldstate)
}
else
#endif
{
/* No.. We are using asynchronous cancellation. If the
* cancellation was pending in this case, then just exit.
*/
{
/* No.. We are using asynchronous cancellation. If the
* cancellation was pending in this case, then just exit.
*/
tcb->flags &= ~TCB_FLAG_CANCEL_PENDING;
tcb->flags &= ~TCB_FLAG_CANCEL_PENDING;
#ifndef CONFIG_DISABLE_PTHREAD
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD)
{
pthread_exit(PTHREAD_CANCELED);
}
else
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD)
{
pthread_exit(PTHREAD_CANCELED);
}
else
#endif
{
exit(EXIT_FAILURE);
}
}
{
exit(EXIT_FAILURE);
}
}
}
}
else if (state == PTHREAD_CANCEL_DISABLE)
else if (state == TASK_CANCEL_DISABLE)
{
/* Set the non-cancelable state */

View file

@ -1,5 +1,5 @@
/****************************************************************************
* sched/pthread/pthread_setcanceltype.c
* sched/task/task_setcanceltype.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -39,32 +39,35 @@
#include <nuttx/config.h>
#include <stdlib.h>
#include <pthread.h>
#include <sched.h>
#include <errno.h>
#include "sched/sched.h"
#include "task/task.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pthread_setcancelstate
* Name: task_setcancelstate
*
* Description:
* The pthread_setcanceltype() function atomically both sets the calling
* The task_setcanceltype() function atomically both sets the calling
* thread's cancelability type to the indicated type and returns the
* previous cancelability type at the location referenced by oldtype
* Legal values for type are PTHREAD_CANCEL_DEFERRED and
* PTHREAD_CANCEL_ASYNCHRONOUS.
* Legal values for type are TASK_CANCEL_DEFERRED and
* TASK_CANCEL_ASYNCHRONOUS.
*
* The cancelability state and type of any newly created threads,
* including the thread in which main() was first invoked, are
* PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_DEFERRED respectively.
* TASK_CANCEL_ENABLE and TASK_CANCEL_DEFERRED respectively.
*
****************************************************************************/
int pthread_setcanceltype(int type, FAR int *oldtype)
int task_setcanceltype(int type, FAR int *oldtype)
{
FAR struct tcb_s *tcb = this_task();
int ret = OK;
@ -81,17 +84,17 @@ int pthread_setcanceltype(int type, FAR int *oldtype)
{
if ((tcb->flags & TCB_FLAG_CANCEL_DEFERRED) != 0)
{
*oldtype = PTHREAD_CANCEL_DEFERRED;
*oldtype = TASK_CANCEL_DEFERRED;
}
else
{
*oldtype = PTHREAD_CANCEL_ASYNCHRONOUS;
*oldtype = TASK_CANCEL_ASYNCHRONOUS;
}
}
/* Set the new cancellation type */
if (type == PTHREAD_CANCEL_ASYNCHRONOUS)
if (type == TASK_CANCEL_ASYNCHRONOUS)
{
/* Clear the deferred cancellation bit */
@ -106,12 +109,24 @@ int pthread_setcanceltype(int type, FAR int *oldtype)
(tcb->flags & TCB_FLAG_NONCANCELABLE) == 0)
{
tcb->flags &= ~TCB_FLAG_CANCEL_PENDING;
pthread_exit(PTHREAD_CANCELED);
/* Exit according to the type of the thread */
#ifndef CONFIG_DISABLE_PTHREAD
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD)
{
pthread_exit(PTHREAD_CANCELED);
}
else
#endif
{
exit(EXIT_FAILURE);
}
}
#endif
}
#ifdef CONFIG_CANCELLATION_POINTS
else if (type == PTHREAD_CANCEL_DEFERRED)
else if (type == TASK_CANCEL_DEFERRED)
{
/* Set the deferred cancellation type */

View file

@ -89,7 +89,6 @@
"pthread_mutex_unlock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t*"
"pthread_once","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_once_t*","CODE void (*)(void)"
"pthread_setaffinity_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SMP)","int","pthread_t","size_t","FAR const cpu_set_t*"
"pthread_setcanceltype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_CANCELLATION_POINTS)","int","int","FAR int*"
"pthread_setschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","int","FAR const struct sched_param*"
"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*"
@ -152,6 +151,7 @@
"task_delete","sched.h","","int","pid_t"
"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*"
"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"

Can't render this file because it has a wrong number of fields in line 2.

View file

@ -89,6 +89,10 @@ SYSCALL_LOOKUP(task_restart, 1, STUB_task_restart)
SYSCALL_LOOKUP(task_setcancelstate, 2, STUB_task_setcancelstate)
SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
# ifdef CONFIG_CANCELLATION_POINTS
SYSCALL_LOOKUP(task_setcanceltype, 2, STUB_task_setcanceltype)
# endif
/* The following can be individually enabled */
#ifdef CONFIG_ARCH_HAVE_VFORK
@ -296,7 +300,6 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
SYSCALL_LOOKUP(pthread_setspecific, 2, STUB_pthread_setspecific)
SYSCALL_LOOKUP(pthread_yield, 0, STUB_pthread_yield)
# ifdef CONFIG_CANCELLATION_POINTS
SYSCALL_LOOKUP(pthread_setcanceltype, 2, STUB_pthread_setcanceltype)
SYSCALL_LOOKUP(pthread_testcancel, 0, STUB_pthread_testcancel)
# endif
# ifdef CONFIG_SMP

View file

@ -100,6 +100,9 @@ uintptr_t STUB_task_setcancelstate(int nbr, uintptr_t parm1,
uintptr_t parm2);
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);
/* The following can be individually enabled */
uintptr_t STUB_vfork(int nbr);
@ -300,8 +303,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_setcanceltype(int nbr, uintptr_t parm1,
uintptr_t parm2);
uintptr_t STUB_pthread_testcancel(int nbr);
uintptr_t STUB_pthread_setaffinity(int nbr, uintptr_t parm1,