mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 02:19:41 +00:00
(svn r23481) -Add: Function to get the CPU core count.
This commit is contained in:
parent
0ca25fb3af
commit
a0f3649c1a
@ -172,3 +172,20 @@ bool GetClipboardContents(char *buffer, size_t buff_len)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uint GetCPUCoreCount()
|
||||||
|
{
|
||||||
|
uint count = 1;
|
||||||
|
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
|
||||||
|
if (MacOSVersionIsAtLeast(10, 5, 0)) {
|
||||||
|
count = [ [ NSProcessInfo processInfo ] activeProcessorCount ];
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
|
||||||
|
count = MPProcessorsScheduled();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
@ -210,3 +210,8 @@ void CSleep(int milliseconds)
|
|||||||
|
|
||||||
const char *FS2OTTD(const char *name) {return name;}
|
const char *FS2OTTD(const char *name) {return name;}
|
||||||
const char *OTTD2FS(const char *name) {return name;}
|
const char *OTTD2FS(const char *name) {return name;}
|
||||||
|
|
||||||
|
uint GetCPUCoreCount()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
@ -28,10 +28,18 @@
|
|||||||
#define HAS_STATVFS
|
#define HAS_STATVFS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(OPENBSD) || defined(__NetBSD__) || defined(__FreeBSD__)
|
||||||
|
#define HAS_SYSCTL
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_STATVFS
|
#ifdef HAS_STATVFS
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_SYSCTL
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __MORPHOS__
|
#ifdef __MORPHOS__
|
||||||
#include <exec/types.h>
|
#include <exec/types.h>
|
||||||
@ -318,3 +326,26 @@ void CSleep(int milliseconds)
|
|||||||
usleep(milliseconds * 1000);
|
usleep(milliseconds * 1000);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
uint GetCPUCoreCount()
|
||||||
|
{
|
||||||
|
uint count = 1;
|
||||||
|
#ifdef HAS_SYSCTL
|
||||||
|
int ncpu = 0;
|
||||||
|
size_t len = sizeof(ncpu);
|
||||||
|
|
||||||
|
if (sysctlbyname("hw.availcpu", &ncpu, &len, NULL, 0) < 0) {
|
||||||
|
sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ncpu > 0) count = ncpu;
|
||||||
|
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||||
|
long res = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
if (res > 0) count = res;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -753,3 +753,11 @@ const char *GetCurrentLocale(const char *)
|
|||||||
static char retbuf[6] = {lang[0], lang[1], '_', country[0], country[1], 0};
|
static char retbuf[6] = {lang[0], lang[1], '_', country[0], country[1], 0};
|
||||||
return retbuf;
|
return retbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint GetCPUCoreCount()
|
||||||
|
{
|
||||||
|
SYSTEM_INFO info;
|
||||||
|
|
||||||
|
GetSystemInfo(&info);
|
||||||
|
return info.dwNumberOfProcessors;
|
||||||
|
}
|
||||||
|
@ -88,4 +88,10 @@ public:
|
|||||||
virtual void SendSignal() = 0;
|
virtual void SendSignal() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get number of processor cores in the system, including HyperThreading or similar.
|
||||||
|
* @return Total number of processor cores.
|
||||||
|
*/
|
||||||
|
uint GetCPUCoreCount();
|
||||||
|
|
||||||
#endif /* THREAD_H */
|
#endif /* THREAD_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user