From time to time I've wanted to set an alarm. But I noticed we didn't have a simple function set for doing so. Such as attaching it to a signal.
I imagine it would be useful to have such a function in the kernal of Exec. But even in the updated OS4 Exec I see none. Whatever is used by Exec for the underlying timer would be hidden away with just functions to set up an alarm and attach to a signal or return a signal.
Sure timer.device can be used but it's over complicated when one just wants a simple alarm. Each timer request needs a few things allocated, attached and opened just for a simple timer. It would be good to have functions to do this and simplify the process.
I use Delay() sometimes but it blocks. And has internal overhead. I'm currently using it in place of some code that works but it locks up my process until finished so not good for multitasking.
What I need is signal tick coming in. Like timer.device signal timer. I can see where this is going.
It might be better to add an alarm function in utility.library, but it would be a good idea to have such a function available.
You could use IDOS->Delay() in a task to avoid blocking. Maybe something similar to this would work:
Allocating a signal instead of using CTRL_E and adding some error checking would be good but you get the idea.
Thanks for the code example xenic. I wonder, does this actually work as is? It creates a task that calls a DOS function but it hasn't opened the dos.library or interface. And the obvious calling Delay() from a task. AmigaOS doesn't exactly have threads like a modern OS unless CreateTaskTags() does something extra special here?
I thought of doing the same sort of thing myself. I also thought utility.library would be a good place.
Another option is lowlevel.library. This provides timer functions and is way easier than timer.device. Just use it to add an interrupt and send a signal. LOL. :-)
The task is the basic unit of execution on an Amiga. An AmigaDOS process structure contains a task structure and adds elements necessary for filesystem interaction. Tasks can't call functions that result in filesystem access but that doesn't mean that all DOS library functions are off limits. The Exec library autodoc claims that a task can't call dos.library functions but that's not entirely true. If you read the AmigaDOS autodoc you will find some functions that are noted as 'task callable'. The Delay() function is one of the task callable functions. Some functions like AddPart() are only marked as task callable as of V50.
The example I gave is from one of my programs but with my function call to another AmigaDOS function replaced with the Delay() function for your use. The dos.library & interface is opened in my main program and I would assume that the Delay() function call is sharing the DOS interface with the main program. It's possible that the 'task' should be calling Obtain() and Release() on the Exec Interface but my programs that use tasks have always worked without that.
I knew some functions were task callable. But was unable to find info on the net for the OS4 functions. Now on OS4 I see a note about Delay() being task callable.
I think you would be right about your task using the DOS interface from the main program. I don't know if the guide compliance is strict about this but I have seen other 68K example code doing it this way. Some libraries can't be called across different tasks and need to be called from the same task context. DOS obviously can. This would be another subject itself.