[util] Add sys function to get cpu count

And use it in qfvis.
This commit is contained in:
Bill Currie 2021-08-13 21:26:48 +09:00
parent d88bd96390
commit 8a5c3c1ac1
3 changed files with 21 additions and 5 deletions

View file

@ -125,6 +125,8 @@ size_t Sys_PageSize (void);
void *Sys_Alloc (size_t size);
void Sys_Free (void *mem, size_t size);
int Sys_ProcessorCount (void);
//
// system IO
//

View file

@ -663,6 +663,23 @@ Sys_Free (void *mem, size_t size)
#endif
}
VISIBLE int
Sys_ProcessorCount (void)
{
int cpus = 1;
#if defined (_SC_NPROCESSORS_ONLN)
cpus = sysconf(_SC_NPROCESSORS_ONLN);
#elif defined (_WIN32)
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
cpus = sysinfo.dwNumberOfProcessors;
#endif
if (cpus < 1) {
cpus = 1;
}
return cpus;
}
VISIBLE void
Sys_DebugLog (const char *file, const char *fmt, ...)
{

View file

@ -40,6 +40,7 @@
#include <unistd.h>
#include "QF/dstring.h"
#include "QF/sys.h"
#include "tools/qfvis/include/options.h"
#include "tools/qfvis/include/vis.h"
@ -105,11 +106,7 @@ default_threads (void)
{
int threads = 1;
#ifdef USE_PTHREADS
# ifdef _SC_NPROCESSORS_ONLN
threads = sysconf(_SC_NPROCESSORS_ONLN);
if (threads < 1)
threads = 1;
# endif
threads = Sys_ProcessorCount ();
#endif
return threads;
}