Re: [AD] PATCH: sleep in xwindows vsync emulation |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: alleg-developers@xxxxxxxxxx
- Subject: Re: [AD] PATCH: sleep in xwindows vsync emulation
- From: Chris <chris.kcat@xxxxxxxxxx>
- Date: Tue, 21 Mar 2006 18:41:08 -0800
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:message-id; b=idHpZLrlulJ8TC57JjQ2Tt6WEu8xmfxkR3WrJJIWdYbvXJu/HHzjBpwdPyNs3KCX99dOq0mRQDO5UedYLwjZFPwycABeMByaS3lcvhYnDkFhJUJEkfqYgdrMDHq6sVoo9jcCThtmx7QB00e63yT7fV+QxmwYt1PowkweJ2p+XsE=
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