Esempio n. 1
0
/**
 * \b atomThreadSwitch
 *
 * This is an internal function not for use by application code.
 *
 * The function is called by the scheduler to perform a context switch.
 * Execution will switch to the new thread's context, therefore the
 * function doesn't actually return until the old thread is scheduled
 * back in.
 *
 * @param[in] old_tcb Pointer to TCB for thread being scheduled out
 * @param[in] new_tcb Pointer to TCB for thread being scheduled in
 *
 * @return None
 */
static void atomThreadSwitch(ATOM_TCB *old_tcb, ATOM_TCB *new_tcb)
{
    /**
     * Check if the new thread is actually the current one, in which
     * case we don't need to do any context switch. This can happen
     * if a thread goes into suspend but is unsuspended again before
     * it is fully scheduled out.
     */
    if (old_tcb != new_tcb)
    {
        /* Set the new currently-running thread pointer */
        curr_tcb = new_tcb;

        /* Call the architecture-specific context switch */
        archContextSwitch (old_tcb, new_tcb);
    }

    /**
     * The context switch shifted execution to a different thread. By the time
     * we get back here, we are running in old_tcb context again. Clear its
     * suspend status now that we're back.
     */
    old_tcb->suspended = FALSE;

}
Esempio n. 2
0
/**
 * \b atomThreadSwitch
 *
 * This is an internal function not for use by application code.
 *
 * The function is called by the scheduler to perform a context switch.
 * Execution will switch to the new thread's context, therefore the
 * function doesn't actually return until the old thread is scheduled
 * back in.
 *
 * @param[in] old_tcb Pointer to TCB for thread being scheduled out
 * @param[in] new_tcb Pointer to TCB for thread being scheduled in
 *
 * @return None
 */
static void atomThreadSwitch(ATOM_TCB *old_tcb, ATOM_TCB *new_tcb)
{
    /**
     * Check if the new thread is actually the current one, in which
     * case we don't need to do any context switch. This can happen
     * if a thread goes into suspend but is unsuspended again before
     * it is fully scheduled out.
     */
    if (old_tcb != new_tcb)
    {
        /* Set the new currently-running thread pointer */
        curr_tcb = new_tcb;

        /**
         * The context switch will shift execution to a different thread. The
         * new thread is now ready to run so clear its suspend status in
         * preparation for it waking up.
         */
        new_tcb->suspended = FALSE;

        /* Call the architecture-specific context switch */
        archContextSwitch (old_tcb, new_tcb);
    }
}