shithub: choc

Download patch

ref: ca3844dc5b138b19259e8dc9daaa397867834a5f
parent: a0062502d183d5d526c1f801b1206234b664898b
author: Simon Howard <[email protected]>
date: Tue Dec 9 15:35:17 EST 2008

Add check for sched_setaffinity to configure and only use it if it is
found. Display a message if we don't have any way to set processor
affinity.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1413

--- a/configure.in
+++ b/configure.in
@@ -54,7 +54,7 @@
 ])
 
 AC_CHECK_HEADERS([linux/kd.h dev/isa/spkrio.h dev/speaker/speaker.h])
-AC_CHECK_FUNCS(mmap)
+AC_CHECK_FUNCS(mmap sched_setaffinity)
 
 # DWF 2008-02-10:  FIXME
 AC_CHECK_LIB(samplerate, src_new)
--- a/src/i_main.c
+++ b/src/i_main.c
@@ -25,6 +25,8 @@
 //-----------------------------------------------------------------------------
 
 
+#include "config.h"
+
 #include "SDL.h"
 
 #include <signal.h>
@@ -32,7 +34,9 @@
 #ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
-#else
+#endif
+
+#ifdef HAVE_SCHED_SETAFFINITY
 #include <unistd.h>
 #include <sched.h>
 #endif
@@ -42,26 +46,36 @@
 #include "m_argv.h"
 #include "d_main.h"
 
-int main(int argc, char **argv) 
-{ 
+#if !defined(_WIN32) && !defined(HAVE_SCHED_SETAFFINITY)
+#warning No known way to set processor affinity on this platform.
+#warning You may experience crashes due to SDL_mixer.
+#endif
+
+int main(int argc, char **argv)
+{
     // save arguments
 
-    myargc = argc; 
-    myargv = argv; 
+    myargc = argc;
+    myargv = argv;
 
+#ifdef _WIN32
+
     // Set the process affinity mask so that all threads
-    // run on the same processor.  This is a workaround for a bug in 
+    // run on the same processor.  This is a workaround for a bug in
     // SDL_mixer that causes occasional crashes.
 
-#ifdef _WIN32
     if (!SetProcessAffinityMask(GetCurrentProcess(), 1))
     {
         fprintf(stderr, "Failed to set process affinity mask (%d)\n",
                 (int) GetLastError());
     }
-#else
-    // POSIX version:
 
+#endif
+
+#ifdef HAVE_SCHED_SETAFFINITY
+
+    // Linux version:
+
     {
         cpu_set_t set;
 
@@ -70,12 +84,13 @@
 
         sched_setaffinity(getpid(), sizeof(set), &set);
     }
+
 #endif
 
     // start doom
- 
-    D_DoomMain (); 
 
+    D_DoomMain ();
+
     return 0;
-} 
+}