[PATCH] Use nanosleep on OS X

Hi,

The current version of SDL_Delay on OS X seems to always sleep at least 10
msec. OS X has nanosleep(), which performs shorter sleeps well. The
attached patch makes it use that one instead of select() as currently.

// Martin
-------------- next part --------------
— SDL-1.2.9-orig/src/timer/linux/SDL_systimer.c 2004-01-04 18:49:19.000000000 +0200
+++ SDL-1.2.9/src/timer/linux/SDL_systimer.c 2005-10-11 16:38:52.000000000 +0300
@@ -55,7 +55,7 @@
/* Linux select() changes its timeout parameter upon return to contain
the remaining time. Most other unixen leave it unchanged or undefined. */
#define SELECT_SETS_REMAINING
-#elif defined(bsdi) || defined(FreeBSD) || defined(__sun)
+#elif defined(bsdi) || defined(FreeBSD) || defined(__sun) || defined(MACOSX)
#define USE_NANOSLEEP
#endif

Martin Storsj? wrote:

The current version of SDL_Delay on OS X seems to always sleep at
least 10 msec. OS X has nanosleep(), which performs shorter sleeps
well. The attached patch makes it use that one instead of select() as
currently.

I was just looking at that code and wondering why it doesn’t use
nanosleep on OpenBSD as well. Is there any reason?

The current version of SDL_Delay on OS X seems to always sleep at least 10
msec. OS X has nanosleep(), which performs shorter sleeps well. The
attached patch makes it use that one instead of select() as currently.

This is in CVS now, thanks!

–ryan.

I was just looking at that code and wondering why it doesn’t use
nanosleep on OpenBSD as well. Is there any reason?

It’s part of the POSIX spec, so it probably should work just about
everywhere. Feel free to submit a patch if you find it works on OpenBSD.

–ryan.

Ryan C. Gordon wrote:

It’s part of the POSIX spec, so it probably should work just about
everywhere. Feel free to submit a patch if you find it works on OpenBSD.

Can we test “Does this system implement the POSIX spec?” and use
nanosleep if it does?

I could easily modify Martin Storsj?'s patch and add “||
defined(OpenBSD)” to it, but then someone would have to do the same
for NetBSD, and that’s getting increasingly messy. And it is pretty silly.

I noticed that OpenBSD’s <sys/unistd.h> has the defines:

#define _POSIX_VERSION 199009L
#define _POSIX2_VERSION 199212L

#if _POSIX_VERSION > 199009L”, maybe, and enable nanosleep on any
system where that succeeds? I am positive this will work on OpenBSD, but
I don’t know how it works on other systems or if it is the right thing
to do.

regards,
Graue