Add ao_wake_task and ao_exit
authorKeith Packard <keithp@keithp.com>
Fri, 16 Oct 2009 03:59:53 +0000 (12:59 +0900)
committerKeith Packard <keithp@keithp.com>
Fri, 16 Oct 2009 03:59:53 +0000 (12:59 +0900)
ao_wake_task signals a specific task to wake up.
ao_exit terminates the current task.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao.h
src/ao_task.c

index b6862a87597fae90c4c03655b9540f63bb8a413a..132711091de385a36a0abe562cb570fbf883a5b6 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -63,6 +63,10 @@ ao_sleep(__xdata void *wchan);
 void
 ao_wakeup(__xdata void *wchan);
 
+/* Wake up a specific task */
+void
+ao_wake_task(__xdata struct ao_task *task);
+
 /* Yield the processor to another task */
 void
 ao_yield(void) _naked;
@@ -71,6 +75,10 @@ ao_yield(void) _naked;
 void
 ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant;
 
+/* Terminate the current task */
+void
+ao_exit(void);
+
 /* Dump task info to console */
 void
 ao_task_info(void);
index 12b73943f0c1c73eec79064c4b97e8f0dc1f21ab..136444b0899ef0b6112544f507f7ca9e8b7d80fa 100644 (file)
@@ -93,7 +93,9 @@ ao_yield(void) _naked
                push    _bp
        _endasm;
 
-       if (ao_cur_task_index != AO_NO_TASK_INDEX)
+       if (ao_cur_task_index == AO_NO_TASK_INDEX)
+               ao_cur_task_index = ao_num_tasks-1;
+       else
        {
                uint8_t stack_len;
                __data uint8_t *stack_ptr;
@@ -198,6 +200,24 @@ ao_wakeup(__xdata void *wchan)
                        ao_tasks[i]->wchan = NULL;
 }
 
+void
+ao_wake_task(__xdata struct ao_task *task)
+{
+       task->wchan = NULL;
+}
+
+void
+ao_exit(void)
+{
+       uint8_t i;
+       ao_num_tasks--;
+       for (i = ao_cur_task_index; i < ao_num_tasks; i++)
+               ao_tasks[i] = ao_tasks[i+1];
+       ao_cur_task_index = AO_NO_TASK_INDEX;
+       ao_yield();
+       /* we'll never get back here */
+}
+
 void
 ao_task_info(void)
 {