mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-13 15:31:28 +00:00
add new numcpus field to the quakeparms structure and detect it during Sys_Init time
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1138 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
2870be2bee
commit
a4b30a4eed
3 changed files with 93 additions and 1 deletions
|
@ -193,6 +193,7 @@ typedef struct
|
||||||
char **argv;
|
char **argv;
|
||||||
void *membase;
|
void *membase;
|
||||||
int memsize;
|
int memsize;
|
||||||
|
int numcpus;
|
||||||
} quakeparms_t;
|
} quakeparms_t;
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
|
@ -155,6 +155,88 @@ int Sys_FileTime (const char *path)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__linux__) || defined(__sun) || defined(sun) || defined(_AIX)
|
||||||
|
static int Sys_NumCPUs (void)
|
||||||
|
{
|
||||||
|
int numcpus = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
return (numcpus < 1) ? 1 : numcpus;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(PLATFORM_OSX)
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#if !defined(HW_AVAILCPU) /* using an ancient SDK? */
|
||||||
|
#define HW_AVAILCPU 25 /* needs >= 10.2 */
|
||||||
|
#endif
|
||||||
|
static int Sys_NumCPUs (void)
|
||||||
|
{
|
||||||
|
int numcpus;
|
||||||
|
int mib[2];
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
#if defined(_SC_NPROCESSORS_ONLN) /* needs >= 10.5 */
|
||||||
|
numcpus = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
if (numcpus != -1)
|
||||||
|
return (numcpus < 1) ? 1 : numcpus;
|
||||||
|
#endif
|
||||||
|
len = sizeof(numcpus);
|
||||||
|
mib[0] = CTL_HW;
|
||||||
|
mib[1] = HW_AVAILCPU;
|
||||||
|
sysctl(mib, 2, &numcpus, &len, NULL, 0);
|
||||||
|
if (sysctl(mib, 2, &numcpus, &len, NULL, 0) == -1)
|
||||||
|
{
|
||||||
|
mib[1] = HW_NCPU;
|
||||||
|
if (sysctl(mib, 2, &numcpus, &len, NULL, 0) == -1)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return (numcpus < 1) ? 1 : numcpus;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(__sgi) || defined(sgi) || defined(__sgi__) /* IRIX */
|
||||||
|
static int Sys_NumCPUs (void)
|
||||||
|
{
|
||||||
|
int numcpus = sysconf(_SC_NPROC_ONLN);
|
||||||
|
if (numcpus < 1)
|
||||||
|
numcpus = 1;
|
||||||
|
return numcpus;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(PLATFORM_BSD)
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
static int Sys_NumCPUs (void)
|
||||||
|
{
|
||||||
|
int numcpus;
|
||||||
|
int mib[2];
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
#if defined(_SC_NPROCESSORS_ONLN)
|
||||||
|
numcpus = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
if (numcpus != -1)
|
||||||
|
return (numcpus < 1) ? 1 : numcpus;
|
||||||
|
#endif
|
||||||
|
len = sizeof(numcpus);
|
||||||
|
mib[0] = CTL_HW;
|
||||||
|
mib[1] = HW_NCPU;
|
||||||
|
if (sysctl(mib, 2, &numcpus, &len, NULL, 0) == -1)
|
||||||
|
return 1;
|
||||||
|
return (numcpus < 1) ? 1 : numcpus;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(__hpux) || defined(__hpux__) || defined(_hpux)
|
||||||
|
#include <sys/mpctl.h>
|
||||||
|
static int Sys_NumCPUs (void)
|
||||||
|
{
|
||||||
|
int numcpus = mpctl(MPC_GETNUMSPUS, NULL, NULL);
|
||||||
|
return numcpus;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* unknown OS */
|
||||||
|
static int Sys_NumCPUs (void)
|
||||||
|
{
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static char cwd[MAX_OSPATH];
|
static char cwd[MAX_OSPATH];
|
||||||
#ifdef DO_USERDIRS
|
#ifdef DO_USERDIRS
|
||||||
static char userdir[MAX_OSPATH];
|
static char userdir[MAX_OSPATH];
|
||||||
|
@ -265,6 +347,8 @@ void Sys_Init (void)
|
||||||
Sys_mkdir (userdir);
|
Sys_mkdir (userdir);
|
||||||
host_parms->userdir = userdir;
|
host_parms->userdir = userdir;
|
||||||
#endif
|
#endif
|
||||||
|
host_parms->numcpus = Sys_NumCPUs ();
|
||||||
|
Sys_Printf("Detected %d CPUs.\n", host_parms->numcpus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sys_mkdir (const char *path)
|
void Sys_mkdir (const char *path)
|
||||||
|
|
|
@ -177,7 +177,7 @@ typedef enum { dpi_unaware = 0, dpi_system_aware = 1, dpi_monitor_aware = 2 } dp
|
||||||
typedef BOOL(*SetProcessDPIAwareFunc)();
|
typedef BOOL(*SetProcessDPIAwareFunc)();
|
||||||
typedef HRESULT(*SetProcessDPIAwarenessFunc)(dpi_awareness value);
|
typedef HRESULT(*SetProcessDPIAwarenessFunc)(dpi_awareness value);
|
||||||
|
|
||||||
void Sys_SetDPIAware (void)
|
static void Sys_SetDPIAware (void)
|
||||||
{
|
{
|
||||||
HMODULE hUser32, hShcore;
|
HMODULE hUser32, hShcore;
|
||||||
SetProcessDPIAwarenessFunc setDPIAwareness;
|
SetProcessDPIAwarenessFunc setDPIAwareness;
|
||||||
|
@ -231,13 +231,19 @@ void Sys_Init (void)
|
||||||
|
|
||||||
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
||||||
{
|
{
|
||||||
|
SYSTEM_INFO info;
|
||||||
WinNT = true;
|
WinNT = true;
|
||||||
if (vinfo.dwMajorVersion >= 6)
|
if (vinfo.dwMajorVersion >= 6)
|
||||||
WinVista = true;
|
WinVista = true;
|
||||||
|
GetSystemInfo(&info);
|
||||||
|
host_parms->numcpus = info.dwNumberOfProcessors;
|
||||||
|
if (host_parms->numcpus < 1)
|
||||||
|
host_parms->numcpus = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WinNT = false; /* Win9x or WinME */
|
WinNT = false; /* Win9x or WinME */
|
||||||
|
host_parms->numcpus = 1;
|
||||||
if ((vinfo.dwMajorVersion == 4) && (vinfo.dwMinorVersion == 0))
|
if ((vinfo.dwMajorVersion == 4) && (vinfo.dwMinorVersion == 0))
|
||||||
{
|
{
|
||||||
Win95 = true;
|
Win95 = true;
|
||||||
|
@ -246,6 +252,7 @@ void Sys_Init (void)
|
||||||
Win95old = true;
|
Win95old = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Sys_Printf("Detected %d CPUs.\n", host_parms->numcpus);
|
||||||
|
|
||||||
if (isDedicated)
|
if (isDedicated)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue