tasks, tasks, tasks

30 views
Skip to first unread message

james cardona

unread,
Nov 26, 2013, 7:30:41 AM11/26/13
to fre...@googlegroups.com
I don't think I fully understand the task system.  Could someone please illuminate? 

I have noticed that when I add task_sleep calls that sometimes the game stops right there and does not advance - this typically happens when I add them to anywhere in the game.c code - for example in end_ball function.  Not sure why this is.

Also, what is the point of these calls?

    task_remove_duration (TASK_DURATION_GAME);

    task_remove_duration (TASK_DURATION_BALL);
    task_duration_expire (TASK_DURATION_BALL);

If the purpose is to kill tasks, would it not be better to handle it with callset_invoke(end_ball)?

Jim

Brian Dominy

unread,
Nov 26, 2013, 7:54:40 AM11/26/13
to fre...@googlegroups.com
Make sure you are adding task_sleep() inside a task context.

Not everything happens inside a task; most callset entry points are not in a task.  Every 16.66ms, the scheduler runs every task that is ready, and then runs the idle callset.  From idle, you can't do task_sleep.  This is where switch scanning and periodics (idle_every_100ms) happen.  So from those places, or any functions that might be called from them, sleep is not allowed.

As far as that goes, it should be ok to sleep in end_ball(), because it gets called from the ball device code which calls event from a per-device task.

However, on the 6809 there is another issue - limited stack space.  If you have a deep call stack, with many nested function calls, and you sleep, there may not be enough room to save the entire call stack.  end_ball is a problem because it gets called from device_remove_live, which is called from a dev_trough_enter, and so on back up the chain.  Generally you can only sleep inside the same function where the task was started.  I suspect that's what is happening.

The duration feature is a way of stopping multiple tasks at the same time.  It would be possible for every module to register an end_ball event and kill its own tasks, but I found that error-prone and forgetting to kill some tasks would lead to strangeness.  Now, every task by default will be stopped at end ball, and to make a task that is immune to that requires writing additional code.

Brian


--
 
---
You received this message because you are subscribed to the Google Groups "FreeWPC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to freewpc+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
- Brian

james cardona

unread,
Nov 26, 2013, 8:32:50 AM11/26/13
to fre...@googlegroups.com, br...@oddchange.com
That clears up a lot.  I have task_sleep calls in a lot of functions that are not tasks.  I guess I should remove them then?  They seem to be working.  By the way, I guess DEFFs and LEFFs are also a form of a task?
Reply all
Reply to author
Forward
0 new messages