MCPcopy Create free account
hub / github.com/apache/nuttx / nxtask_delete

Function nxtask_delete

sched/task/task_delete.c:67–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65 ****************************************************************************/
66
67int nxtask_delete(pid_t pid)
68{
69 FAR struct tcb_s *dtcb;
70 FAR struct tcb_s *rtcb;
71
72 /* Check if the task to delete is the calling task: PID=0 means to delete
73 * the calling task. In this case, task_delete() is much like exit()
74 * except that it obeys the cancellation semantics.
75 */
76
77 rtcb = this_task();
78 if (pid == 0)
79 {
80 pid = rtcb->pid;
81 }
82
83 /* Get the TCB of the task to be deleted */
84
85 dtcb = nxsched_get_tcb(pid);
86 if (dtcb == NULL)
87 {
88 /* The pid does not correspond to any known thread. The task
89 * has probably already exited.
90 */
91
92 return -ESRCH;
93 }
94
95 /* Only tasks and kernel threads can be deleted with this interface
96 * (The semantics of the call should be sufficient to prohibit this).
97 */
98
99 DEBUGASSERT((dtcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD);
100
101 /* Non-privileged tasks and pthreads may not delete privileged kernel
102 * threads.
103 *
104 * REVISIT: We will need to look at this again in the future if/when
105 * permissions are supported and a user task might also be privileged.
106 */
107
108 if (((rtcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL) &&
109 ((dtcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL))
110 {
111 return -EACCES;
112 }
113
114 /* Check if the task to delete is the calling task */
115
116 if (pid == rtcb->pid)
117 {
118 /* If it is, then what we really wanted to do was exit. Note that we
119 * don't bother to unlock the TCB since it will be going away.
120 */
121
122 _exit(EXIT_SUCCESS);
123 }
124

Callers 3

task_deleteFunction · 0.85
cxd5610_gnss_finalizeFunction · 0.85

Calls 5

this_taskFunction · 0.85
nxsched_get_tcbFunction · 0.85
nxnotify_cancellationFunction · 0.85
nxtask_terminateFunction · 0.85
_exitFunction · 0.70

Tested by

no test coverage detected