From: Lauri Kasanen Date: Sat, 3 Mar 2012 10:44:50 +0000 (+0200) Subject: Automatically determine the number of threads on linux X-Git-Tag: xonotic-v0.6.0~2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=053ca4041b3fe0f69bd325df7fd3c20446351e19;p=xonotic%2Fnetradiant.git Automatically determine the number of threads on linux Signed-off-by: Lauri Kasanen --- diff --git a/tools/quake3/common/threads.c b/tools/quake3/common/threads.c index 7f404a4f..1c8e7e75 100644 --- a/tools/quake3/common/threads.c +++ b/tools/quake3/common/threads.c @@ -426,17 +426,26 @@ void RunThreadsOn (int workcnt, qboolean showpacifier, void(*func)(int)) #if defined(__linux__) || (defined(__APPLE__) && !MAC_STATIC_HACK) #define USED -int numthreads = 4; +#include + +int numthreads = -1; void ThreadSetDefault (void) { if (numthreads == -1) // not set manually { - /* default to one thread, only multi-thread when specifically told to */ - numthreads = 1; +#ifdef _SC_NPROCESSORS_CONF + long cpus = sysconf(_SC_NPROCESSORS_CONF); + if (cpus > 0) + numthreads = cpus; + else +#endif + /* can't detect, so default to four threads */ + numthreads = 4; } - if(numthreads > 1) - Sys_Printf("threads: %d\n", numthreads); + + if(numthreads > 1) + Sys_Printf("threads: %d\n", numthreads); } #include