[interfacekit] BLooper in BWindow
- From: "Axel Dörfler" <axeld@xxxxxxxxxxxxxxxx>
- To: "OpenBeOS Interface Kit" <interfacekit@xxxxxxxxxxxxx>
- Date: Fri, 23 May 2003 19:50:09 +0200 CEST
I just got another "idea" - much better than snoozing for a while (and
then checking the ports) would be to wait for a shorter amount of time
on one port.
Just snoozing would have many disadvantages, for example it could slow
down message handling.
In my first mail, I suggested you to use another BLooper for this -
while this would probably be the cleanest solution, it would create the
need for two threads for just one window, which is too generous for a
resource as limited as this.
To implement something like this, I would select the port where it is
crucial to react quickly on messages, like incoming mouse positions, or
whatever you prefer. When you got a message at that port, or the
read=5Fport=5Fetc() function timed out, I would then check for messages on
the other port with a timeout of zero.
So it would look like this (in pseudo code):
waitFor =3D reasonableAmountOfTime;
while (isRunning) {
status =3D read=5Fport=5Fetc(port1, B=5FRELATIVE=5FTIMEOUT, waitFor);
if (status =3D=3D B=5FOK)
handlePort1();
status =3D read=5Fport=5Fetc(port2, B=5FRELATIVE=5FTIMEOUT, 0);
if (status =3D=3D B=5FOK)
handlePort2();
}
If you need better timing, I would use an absolute timeout with an
increasing amount like:
while (isRunning) {
waitUntil +=3D waitFor;
...
}
Until we have wait=5Ffor=5Fmultiple=5Fobjects(), I think this is the cleanest
solution we can come up with for a BWindow.
Thoughts=3F
Adios...
Axel.
Other related posts:
- » [interfacekit] BLooper in BWindow