diff options
| author | Keith Packard <keithp@keithp.com> | 2012-08-26 09:49:34 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2012-08-26 09:49:34 -0700 | 
| commit | d13d0fbfcb0fd6d8a1af46f6270a968d746c830e (patch) | |
| tree | 2d11bfe1903361b07a1ce31c95db755f8e7d9f8d | |
| parent | 1c9baa88d6cd931c66d453674322908eb267ba4c (diff) | |
altos: Make ao_cur_task_index track ao_cur_task in ao_yield
This keeps the two main task references (index and pointer) in
agreement during task switching, avoiding an extra assignment at the
end of the task switching loop.
Signed-off-by: Keith Packard <keithp@keithp.com>
| -rw-r--r-- | src/core/ao_task.c | 29 | 
1 files changed, 13 insertions, 16 deletions
| diff --git a/src/core/ao_task.c b/src/core/ao_task.c index 4011a36e..4593bd79 100644 --- a/src/core/ao_task.c +++ b/src/core/ao_task.c @@ -82,39 +82,36 @@ ao_yield(void) ao_arch_naked_define  	ao_arch_isr_stack(); -#if CHECK_STACK +#if AO_CHECK_STACK  	in_yield = 1;  #endif  	/* Find a task to run. If there isn't any runnable task,  	 * this loop will run forever, which is just fine  	 */  	{ -		__pdata uint8_t	ao_next_task_index = ao_cur_task_index; +		__pdata uint8_t	ao_last_task_index = ao_cur_task_index;  		for (;;) { -			++ao_next_task_index; -			if (ao_next_task_index == ao_num_tasks) -				ao_next_task_index = 0; +			++ao_cur_task_index; +			if (ao_cur_task_index == ao_num_tasks) +				ao_cur_task_index = 0; + +			ao_cur_task = ao_tasks[ao_cur_task_index]; -			ao_cur_task = ao_tasks[ao_next_task_index]; -			if (ao_cur_task->wchan == NULL) { -				ao_cur_task_index = ao_next_task_index; +			/* Check for ready task */ +			if (ao_cur_task->wchan == NULL)  				break; -			}  			/* Check if the alarm is set for a time which has passed */  			if (ao_cur_task->alarm && -			    (int16_t) (ao_time() - ao_cur_task->alarm) >= 0) { -				ao_cur_task_index = ao_next_task_index; +			    (int16_t) (ao_time() - ao_cur_task->alarm) >= 0)  				break; -			}  			/* Enter lower power mode when there isn't anything to do */ -			if (ao_next_task_index == ao_cur_task_index) { +			if (ao_cur_task_index == ao_last_task_index)  				ao_arch_cpu_idle(); -			}  		}  	} -#if CHECK_STACK +#if AO_CHECK_STACK  	cli();  	in_yield = 0;  #endif @@ -177,7 +174,7 @@ ao_exit(void)  void  ao_task_info(void)  { -	uint8_t	i; +	uint8_t		i;  	__xdata struct ao_task *task;  	for (i = 0; i < ao_num_tasks; i++) { | 
