We don't have a simple alarm function?

7 posts / 0 new
Last post
hypex
hypex's picture
Offline
Last seen: 3 weeks 14 hours ago
Joined: 2011-09-09 16:20
We don't have a simple alarm function?

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.

ZeroG
ZeroG's picture
Offline
Last seen: 2 weeks 3 days ago
Joined: 2018-08-20 18:35
Re: We don't have a simple alarm function?

IDOS->Delay() maybe?

hypex
hypex's picture
Offline
Last seen: 3 weeks 14 hours ago
Joined: 2011-09-09 16:20
Re: We don't have a simple alarm function?

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.

xenic
xenic's picture
Offline
Last seen: 3 weeks 2 days ago
Joined: 2011-05-07 04:52
Re: We don't have a simple alarm function?

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:

  1. In you main program somewhere:
  2.  
  3. struct Task *alarm = NULL;
  4. IExec->CreateTaskTags("MyClockTask", 0,
  5. clock_task, 16384,
  6. AT_Param1, (ULONG)IExec->FindTask(NULL),
  7. TAG_DONE);
  8. alarm = IExec->FindTask("MyClockTask");
  9.  
  10. Before leaving your main program:
  11.  
  12. IExec->Signal(alarm, SIGBREAKF_CTRL_C);
  13. IDOS->Delay(100);
  14.  
  15. The alarm task:
  16.  
  17. void clock_task(struct Task *parent)
  18. {
  19. struct Task *task = IExec->FindTask(NULL);
  20.  
  21. for (;;)
  22. {
  23. if (IDOS->CheckSignal(SIGBREAKF_CTRL_C)) break;
  24. IDOS->Delay(100);
  25. IExec->Signal(parent, SIGBREAKF_CTRL_E);
  26. {
  27.  
  28. IExec->DeleteTask(task);
  29. }

Allocating a signal instead of using CTRL_E and adding some error checking would be good but you get the idea.

X1000 - OS 4.1FE
hypex
hypex's picture
Offline
Last seen: 3 weeks 14 hours ago
Joined: 2011-09-09 16:20
Re: We don't have a simple alarm function?

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. :-)

xenic
xenic's picture
Offline
Last seen: 3 weeks 2 days ago
Joined: 2011-05-07 04:52
Re: We don't have a simple alarm function?

@hypex
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.

X1000 - OS 4.1FE
hypex
hypex's picture
Offline
Last seen: 3 weeks 14 hours ago
Joined: 2011-09-09 16:20
Re: We don't have a simple alarm function?

@xenic

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.

Log in or register to post comments