mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 07:11:41 +00:00
[util] Add sys function to get cpu count
And use it in qfvis.
This commit is contained in:
parent
d88bd96390
commit
8a5c3c1ac1
3 changed files with 21 additions and 5 deletions
|
@ -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
|
||||
//
|
||||
|
|
|
@ -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, ...)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue