# cat&mouse / setitimer

Holger Veit (Holger.Veit@gmd.de)
Sat, 13 Sep 1997 20:59:31 +0200 (MET DST)

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Faye Pearson: "[XFreeOS2] CL-GD 5446 more information"
- Previous message: Anssi Saari: "Re: [XFreeOS2] Font problem with 3.3.1"

Re: [XFreeOS2] MIT shm
Rodney R. Korte (rkorte@psu.edu)
Mon, 29 Dec 1997 10:39:30 +0100 (MET)
[set/getitimer stuff]
> I ran into this problem with the xpilot server. I worked up
> two work-arounds for it: 1) use a semaphore, a timer, and another
> thread as you describe; 2) use a second thread and just call
> DosSleep( ), then do something.
> > Neither solution is satisfactory if you need decent accuracy
> below 1/10 second, IMO, as is required in the xpilot server.
I think this applies only to high-speed games like your xpilot,
Enlightment is unlikely to have this problem.
[...]
> I think that to do an itimer bit, emx will have to use
> the new high-resolution timer device driver stuff developed
> by Timur Tabi for multimedia I/O, which I believe is also in
> Warp 4 now. This should be a good subject for the EMX list.
This is something that - if at all - should be a part of the
EMX runtime system, because this timer is a scarce resource, and
mustn't be allocated exclusively.
> I'm not on it, but perhaps other interested parties should
> poke around there for a discussion on this topic? Maybe EM
> has committed to (or refused to do) this project already.
Not that I am aware of (that it has been discussed already).
You'll now find a small port of oneko on the ported software page, which is
the well-known cat hunting the mouse cursor. I've ported this as a quickie
mainly to demonstate how one can replace common occurrences of setitimer(2)
which was asked some days ago in this list.
To explain how it works here, see the source code (ftp://set.gmd.de/pub/misc/XFree86OS2/ports/oneko-1.1.tgz)
and the diffs (in the oneko.zip file):

setitimer was used here to produce a periodic SIGALRM event faster than 1 sec.
I replaced the setitimer call with a beginthread which runs in an endless
loop (if this periodic timer is to be stopped in some other application,
you have to end such a thread somehow, of course):
void itimerthread(void* dummy) {
while(1) {
_sleep2(numer_of_milliseconds);
/* call SIGALRM handler */
itimerflag = 1; /* see below */
}
}
This thread _sleep2's for the specified interval time and would then call
the signal function which is called by a SIGALRM signal. In this example,
this is a no-op, because the side effect of SIGALRM is used here. Somewhere
in the code is a pause() call, which waits until a signal happens. I
replaced this pause() with a wait for a variable (an OS/2 semaphore would be
cleaner, but this here is not critical):
while (itimerflag==0) DosSleep(0); /* could be DosSleep(1) as well? */
itimerflag = 0;
and added a itimerflag=1 (see above) after the _sleep2 in the itimer thread.
This will animate the neko cat.

Such a mechanism might be worthwhile in many ports, maybe some of you can use
it.

    --
             Dr.-Ing. Holger Veit             | INTERNET: Holger.Veit"at"gmd.de
    |  |   / GMD - German National Research   | Phone: (+49) 2241 14 2448
    |__|  /  Center for Information Technology| Fax:   (+49) 2241 14 2242
    |  | /   Schloss Birlinghoven             |  Get XFree86/OS2 Bugfix Version
    |  |/    D-53754 Sankt Augustin, Germany  |    V3.3.1 from ftp.xfree86.org
             WWW: http://borneo.gmd.de/~veit/ | /pub/XFree86/3.3.1/binaries/OS2

- Next message: Faye Pearson: "[XFreeOS2] CL-GD 5446 more information"
- Previous message: Anssi Saari: "Re: [XFreeOS2] Font problem with 3.3.1"