Re: [AD] PATCH: sleep in xwindows vsync emulation

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


On Tuesday 21 March 2006 04:47, Hans de Goede wrote:
> I noticed while porting a game to allegro that it was a cpuhog, it
> truned out that it used the vsync() call to regulate its framerate and
> that the current vsync emulation in xwin.c busy waits, which is really
> not the unix way.
>
> Attached a simple patch which causes allegro to sleep
> while waiting in the vsync emulation function.

Is it really safe to assume vsync should rest the cpu? From my experiences on 
Windows, it doesn't. In fact, if the return to the program isn't controlled 
by the actual sync interrupt on such platforms, it'd miss the actual sync. 
Granted X only emulates this, but it should still return ASAP once the 
retrace counter ticks.

Attached is a patch that uses sched_yield() instead, which should keep the 
excessive waiting down, while keeping vsync responsive to return ASAP.
Index: src/x/xwin.c
===================================================================
--- src/x/xwin.c	(revision 5716)
+++ src/x/xwin.c	(working copy)
@@ -2198,8 +2198,8 @@
       XSync(_xwin.display, False);
       XUNLOCK();
 
-      do {
-      } while (retrace_count == prev);
+      while (retrace_count == prev)
+         sched_yield();
    }
    else {
       /* This does not wait for the VBI - but it waits until X11 has


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