mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-09 01:01:07 +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;
|
||||
void *membase;
|
||||
int memsize;
|
||||
int numcpus;
|
||||
} quakeparms_t;
|
||||
|
||||
#include "common.h"
|
||||
|
|
|
@ -155,6 +155,88 @@ int Sys_FileTime (const char *path)
|
|||
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];
|
||||
#ifdef DO_USERDIRS
|
||||
static char userdir[MAX_OSPATH];
|
||||
|
@ -265,6 +347,8 @@ void Sys_Init (void)
|
|||
Sys_mkdir (userdir);
|
||||
host_parms->userdir = userdir;
|
||||
#endif
|
||||
host_parms->numcpus = Sys_NumCPUs ();
|
||||
Sys_Printf("Detected %d CPUs.\n", host_parms->numcpus);
|
||||
}
|
||||
|
||||
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 HRESULT(*SetProcessDPIAwarenessFunc)(dpi_awareness value);
|
||||
|
||||
void Sys_SetDPIAware (void)
|
||||
static void Sys_SetDPIAware (void)
|
||||
{
|
||||
HMODULE hUser32, hShcore;
|
||||
SetProcessDPIAwarenessFunc setDPIAwareness;
|
||||
|
@ -231,13 +231,19 @@ void Sys_Init (void)
|
|||
|
||||
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
||||
{
|
||||
SYSTEM_INFO info;
|
||||
WinNT = true;
|
||||
if (vinfo.dwMajorVersion >= 6)
|
||||
WinVista = true;
|
||||
GetSystemInfo(&info);
|
||||
host_parms->numcpus = info.dwNumberOfProcessors;
|
||||
if (host_parms->numcpus < 1)
|
||||
host_parms->numcpus = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
WinNT = false; /* Win9x or WinME */
|
||||
host_parms->numcpus = 1;
|
||||
if ((vinfo.dwMajorVersion == 4) && (vinfo.dwMinorVersion == 0))
|
||||
{
|
||||
Win95 = true;
|
||||
|
@ -246,6 +252,7 @@ void Sys_Init (void)
|
|||
Win95old = true;
|
||||
}
|
||||
}
|
||||
Sys_Printf("Detected %d CPUs.\n", host_parms->numcpus);
|
||||
|
||||
if (isDedicated)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue