From ca3844dc5b138b19259e8dc9daaa397867834a5f Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Tue, 9 Dec 2008 20:35:17 +0000 Subject: 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 --- configure.in | 2 +- src/i_main.c | 39 +++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/configure.in b/configure.in index 43e3438f..83c4739a 100644 --- a/configure.in +++ b/configure.in @@ -54,7 +54,7 @@ AC_CHECK_LIB(SDL_net,SDLNet_UDP_Send,[ ]) 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) diff --git a/src/i_main.c b/src/i_main.c index 74b164b1..c103296b 100644 --- a/src/i_main.c +++ b/src/i_main.c @@ -25,6 +25,8 @@ //----------------------------------------------------------------------------- +#include "config.h" + #include "SDL.h" #include @@ -32,7 +34,9 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include -#else +#endif + +#ifdef HAVE_SCHED_SETAFFINITY #include #include #endif @@ -42,25 +46,35 @@ #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 @@ int main(int argc, char **argv) sched_setaffinity(getpid(), sizeof(set), &set); } + #endif // start doom - - D_DoomMain (); + + D_DoomMain (); return 0; -} +} -- cgit v1.2.3