atomkernel: Support thread entry points running to completion. Ports which use a thread_shell() can allow the entry point to finish and return back to the thread_shell(), which sets the terminated flag and calls the scheduler to force another thread to be scheduled in. Currently implemented in the ARM and AVR ports.

This commit is contained in:
Kelvin Lawson
2016-05-23 20:50:51 +01:00
parent e99d05582f
commit b0afc266d1
4 changed files with 9 additions and 6 deletions

View File

@@ -77,6 +77,7 @@ typedef struct atom_tcb
uint8_t suspended; /* TRUE if task is currently suspended */
uint8_t suspend_wake_status; /* Status returned to woken suspend calls */
ATOM_TIMER *suspend_timo_cb; /* Callback registered for suspension timeouts */
uint8_t terminated; /* TRUE if task is being terminated (run to completion) */
/* Details used if thread stack-checking is required */
#ifdef ATOM_STACK_CHECKING

View File

@@ -241,10 +241,11 @@ void atomSched (uint8_t timer_tick)
CRITICAL_START ();
/**
* If the current thread is going into suspension, then
* unconditionally dequeue the next thread for execution.
* If the current thread is going into suspension or is being
* terminated (run to completion), then unconditionally dequeue
* the next thread for execution.
*/
if (curr_tcb->suspended == TRUE)
if ((curr_tcb->suspended == TRUE) || (curr_tcb->terminated == TRUE))
{
/**
* Dequeue the next ready to run thread. There will always be

View File

@@ -97,7 +97,7 @@ static void thread_shell (void)
_reclaim_reent (&(curr_tcb->port_priv.reent));
/* Thread has run to completion: remove it from the ready list */
curr_tcb->suspended = TRUE;
curr_tcb->terminated = TRUE;
atomSched (FALSE);
}

View File

@@ -111,8 +111,9 @@ static void thread_shell (void)
curr_tcb->entry_point(curr_tcb->entry_param);
}
/* Not reached - threads should never return from the entry point */
/* Thread has run to completion: remove it from the ready list */
curr_tcb->terminated = TRUE;
atomSched (FALSE);
}