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

Function up_switch_context

arch/sim/src/sim/sim_switchcontext.c:57–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55 ****************************************************************************/
56
57void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
58{
59 int ret;
60
61 sinfo("Unblocking TCB=%p\n", tcb);
62
63 /* Are we in an interrupt handler? */
64
65 if (up_interrupt_context())
66 {
67 /* Yes, then we have to do things differently.
68 * Just copy the current_regs into the OLD rtcb.
69 */
70
71 sim_savestate(rtcb->xcp.regs);
72
73 /* Then switch contexts */
74
75 sim_restorestate(tcb->xcp.regs);
76
77 return;
78 }
79
80 /* Copy the exception context into the TCB of the task that was
81 * previously active. if sim_saveusercontext returns a non-zero value,
82 * then this is really the previously running task restarting!
83 */
84
85 sim_saveusercontext(rtcb->xcp.regs, ret);
86 if (ret == 0)
87 {
88 sinfo("New Active Task TCB=%p\n", tcb);
89
90 /* Update scheduler parameters */
91
92 nxsched_switch_context(rtcb, tcb);
93
94 /* Restore the cpu lock */
95
96 restore_critical_section(tcb, this_cpu());
97
98 /* Record the new "running" task */
99
100 g_running_tasks[this_cpu()] = tcb;
101
102 /* Then switch contexts */
103
104 sim_fullcontextrestore(tcb->xcp.regs);
105 }
106 else
107 {
108#ifdef CONFIG_ENABLE_ALL_SIGNALS
109 /* The way that we handle signals in the simulation is kind of
110 * a kludge. This would be unsafe in a truly multi-threaded,
111 * interrupt driven environment.
112 */
113
114 sim_sigdeliver();

Callers 15

nxsem_wait_slowFunction · 0.50
nxsem_post_slowFunction · 0.50
nxsem_wait_irqFunction · 0.50
nxsched_abstick_sleepFunction · 0.50
nxsched_wakeupFunction · 0.50
sched_unlockFunction · 0.50
nxsched_suspendFunction · 0.50
nxtask_activateFunction · 0.50

Calls 3

nxsched_switch_contextFunction · 0.85
sim_sigdeliverFunction · 0.85
up_interrupt_contextFunction · 0.50

Tested by

no test coverage detected