Re: [AD] XIM patch for Allegro 4.1.x

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Elias Pschernig a écrit :

> > (1) Unfortunately, drawing from a callback doesn't work, not even in X
> > :-(. The program sometimes aborts when I press keys, or hold them down.
> > Doesn't always happen, though...
>
> Um. I guess this isn't such a good idea then. But I wonder why it aborts
> - it seems to work here. All X11 drawing should use a pthread lock, so
> even when drawing from the input thread, it should work in this case,
> where nothing else (e.g. the mouse) is drawn. I guess it will work once
> we clarify that _xwin_in_gfx_call issue. But for now, I'll not do any
> changes to exkeys.

Maybe this is related to my responsiveness problem... I'm using Xorg 6.8.0, by 
the way, that might make a difference.

> > (2b) Also, with or without the keypress_handler, this part of the example
> > is a bit "unresponsive": when pressing a number key, there is sometimes a
> > small delay before the appearance / disappearance of the number on the
> > screen. Again, this doesn't happen anymore if I put a rest(0) in the
> > loop. But IIRC, unresponsive input when drawing in a tigh loop is a long
> > standing issue, no ?
>
> Only with the signals version, not with the pthread version. But depends
> on the kernel settings I guess.. mine seems to schedule the input thread
> as responsive despite the spinlocking main thread - I can't notice any
> responsiveness loss in the numbers test - just the fans start noising
> loud. Are you using a 2.4.x kernel maybe? That did a context switch
> every time a pthread lock was encountered..

Well, I'm using a vanilla 2.6.9 kernel. The kernel is preemptible, if that 
matters. Anyway, attached is a *weird*, minimal test case.

It is highly unresponsive: it can sometime take more than a second before key 
presses/releases appear on screen. However, if at the beginning, "rest(1)" is 
replaced by "rest(0)", or removed altogether, then the program becomes 
perfectly responsive. The problem seems to be caused by the select() call 
inside rest, because if rest() is replaced by rest_callback(), which uses 
gettimeofday, then the program works fine.

The question is, why would calling rest in the beginning of the program slow 
down a loop later on ?!? This is so weird that if nobody can reproduce it, 
I'll assume this is a problem with my system being somehow broken...

-- 
Julien Cugnière
#include "allegro.h"

int main(void)
{
   char buf[128];

   allegro_init();
   install_keyboard();
   set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
   clear_to_color(screen, makecol(255, 255, 255));

   while (!keypressed())
	   rest(1);

   do {
      if (key[KEY_0]) buf[0] = '0'; else buf[0] = ' ';
      if (key[KEY_1]) buf[1] = '1'; else buf[1] = ' ';
      if (key[KEY_2]) buf[2] = '2'; else buf[2] = ' ';
      if (key[KEY_3]) buf[3] = '3'; else buf[3] = ' ';
      if (key[KEY_4]) buf[4] = '4'; else buf[4] = ' ';
      if (key[KEY_5]) buf[5] = '5'; else buf[5] = ' ';
      if (key[KEY_6]) buf[6] = '6'; else buf[6] = ' ';
      if (key[KEY_7]) buf[7] = '7'; else buf[7] = ' ';
      if (key[KEY_8]) buf[8] = '8'; else buf[8] = ' ';
      if (key[KEY_9]) buf[9] = '9'; else buf[9] = ' ';
      buf[10] = 0;
      acquire_screen();
      textprintf_ex(screen, font, 8, SCREEN_H-16, makecol(0,0,0), makecol(255, 255, 255),
                    "[%d] %s", (retrace_count/6) % 10, buf);
	  release_screen();
   } while (!key[KEY_ESC]);

   return 0;
}
END_OF_MAIN()


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/