Added multitask example

This commit is contained in:
Luxferre
2022-08-14 18:08:07 +03:00
parent 7e7544a15a
commit 71eb5bafa8
2 changed files with 34 additions and 3 deletions
+6 -3
View File
@@ -452,9 +452,12 @@ ushort equi_find_free_task_slot() {
/* Find the next active task in the table, round-robin fashion */
struct EquiCtx* equi_find_next_task() {
ushort oldtaskid = ram.taskid; /* save the current one to avoid deadlocks */
while(!ram.tasks[ram.taskid].active) {
while(1) {
++ram.taskid;
if(ram.taskid == EQUI_TASKS_MAX) ram.taskid = 0;
if(ram.taskid == EQUI_TASKS_MAX)
ram.taskid = 0;
if(ram.tasks[ram.taskid].active)
break;
if(ram.taskid == oldtaskid) /* found no active tasks, bailing out */
return NULL;
}
@@ -488,7 +491,7 @@ void equi_main_loop() {
while(1) { /* iterate over the instructions in the command buffer */
curtask = equi_find_next_task(); /* attempt to switch the context on every iteration */
if(curtask == NULL) break; /* exit the main loop when no tasks are left */
instr = flatram[++curtask->pc];
instr = flatram[++(curtask->pc)];
/* silently exit on zero or FF */
if(instr == 0 || instr == 0xFFu)
curtask->active = 0;