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

Function nxtask_exit

sched/task/task_exit.c:75–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73 ****************************************************************************/
74
75int nxtask_exit(void)
76{
77 FAR struct tcb_s *dtcb;
78 FAR struct tcb_s *rtcb;
79 int ret;
80#ifdef CONFIG_SMP
81 /* Avoid using this_task() because it may assume a state that is not
82 * appropriate for an exiting task.
83 */
84
85 dtcb = current_task(this_cpu());
86#else
87 dtcb = this_task();
88#endif
89
90 sinfo("%s pid=%d,TCB=%p\n", get_task_name(dtcb),
91 dtcb->pid, dtcb);
92
93 /* Remove the TCB of the current task from the ready-to-run list. A
94 * context switch will definitely be necessary -- that must be done
95 * by the architecture-specific logic.
96 *
97 * nxsched_remove_readytorun will mark the task at the head of the
98 * ready-to-run with state == TSTATE_TASK_RUNNING
99 */
100
101 nxsched_remove_self(dtcb);
102
103 /* Get the new task at the head of the ready to run list */
104
105#ifdef CONFIG_SMP
106 rtcb = current_task(this_cpu());
107#else
108 rtcb = this_task();
109#endif
110
111 /* We are now in a bad state -- the head of the ready to run task list
112 * does not correspond to the thread that is running. Disabling pre-
113 * emption on this TCB and marking the new ready-to-run task as not
114 * running.
115 *
116 * We disable pre-emption here by directly incrementing the lockcount
117 * (vs. calling sched_lock()).
118 */
119
120 rtcb->lockcount++;
121
122 rtcb->task_state = TSTATE_TASK_READYTORUN;
123
124#ifdef CONFIG_SMP
125 /* NOTE:
126 * During nxtask_terminate(), enter_critical_section() will be called
127 * to deallocate tcb. However, this would acquire g_cpu_irqlock if
128 * rtcb->irqcount = 0, event though we are in critical section.
129 * To prevent from acquiring, increment rtcb->irqcount here.
130 */
131
132 rtcb->irqcount++;

Callers 15

up_exitFunction · 0.85
up_exitFunction · 0.85
up_exitFunction · 0.85
up_exitFunction · 0.85
up_exitFunction · 0.85
up_exitFunction · 0.85
up_exitFunction · 0.85
up_exitFunction · 0.85
up_exitFunction · 0.85
up_exitFunction · 0.85
_exitFunction · 0.85
up_exitFunction · 0.85

Calls 6

this_taskFunction · 0.85
get_task_nameFunction · 0.85
nxsched_remove_selfFunction · 0.85
nxsched_switch_contextFunction · 0.85
sched_note_stopFunction · 0.85
nxsched_release_tcbFunction · 0.85

Tested by

no test coverage detected