mirror of https://github.com/OpenTTD/OpenTTD
Codechange: C++11 STL has a function for getting the number of CPU cores.
parent
ae748166d0
commit
967b27a2c1
|
@ -206,23 +206,6 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||||
}
|
}
|
||||||
#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 = (uint)[ [ NSProcessInfo processInfo ] activeProcessorCount ];
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
|
|
||||||
count = MPProcessorsScheduled();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a font is a monospace font.
|
* Check if a font is a monospace font.
|
||||||
* @param name Name of the font.
|
* @param name Name of the font.
|
||||||
|
|
|
@ -208,11 +208,6 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSOpenBrowser(const char *url)
|
void OSOpenBrowser(const char *url)
|
||||||
{
|
{
|
||||||
// stub only
|
// stub only
|
||||||
|
|
|
@ -274,35 +274,6 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||||
|
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
uint GetCPUCoreCount()
|
|
||||||
{
|
|
||||||
uint count = 1;
|
|
||||||
#ifdef HAS_SYSCTL
|
|
||||||
int ncpu = 0;
|
|
||||||
size_t len = sizeof(ncpu);
|
|
||||||
|
|
||||||
#ifdef OPENBSD
|
|
||||||
int name[2];
|
|
||||||
name[0] = CTL_HW;
|
|
||||||
name[1] = HW_NCPU;
|
|
||||||
if (sysctl(name, 2, &ncpu, &len, NULL, 0) < 0) {
|
|
||||||
ncpu = 0;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (sysctlbyname("hw.availcpu", &ncpu, &len, NULL, 0) < 0) {
|
|
||||||
sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);
|
|
||||||
}
|
|
||||||
#endif /* #ifdef OPENBSD */
|
|
||||||
|
|
||||||
if (ncpu > 0) count = ncpu;
|
|
||||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
|
||||||
long res = sysconf(_SC_NPROCESSORS_ONLN);
|
|
||||||
if (res > 0) count = res;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSOpenBrowser(const char *url)
|
void OSOpenBrowser(const char *url)
|
||||||
{
|
{
|
||||||
pid_t child_pid = fork();
|
pid_t child_pid = fork();
|
||||||
|
|
|
@ -725,14 +725,6 @@ const char *GetCurrentLocale(const char *)
|
||||||
return retbuf;
|
return retbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint GetCPUCoreCount()
|
|
||||||
{
|
|
||||||
SYSTEM_INFO info;
|
|
||||||
|
|
||||||
GetSystemInfo(&info);
|
|
||||||
return info.dwNumberOfProcessors;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static WCHAR _cur_iso_locale[16] = L"";
|
static WCHAR _cur_iso_locale[16] = L"";
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,6 @@ inline void CSleep(int milliseconds)
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
|
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get number of processor cores in the system, including HyperThreading or similar.
|
|
||||||
* @return Total number of processor cores.
|
|
||||||
*/
|
|
||||||
uint GetCPUCoreCount();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name the thread this function is called on for the debugger.
|
* Name the thread this function is called on for the debugger.
|
||||||
* @param name Name to set for the thread..
|
* @param name Name to set for the thread..
|
||||||
|
|
|
@ -1149,7 +1149,7 @@ const char *VideoDriver_Win32::Start(const char * const *parm)
|
||||||
|
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
|
|
||||||
_draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL && GetCPUCoreCount() > 1;
|
_draw_threaded = GetDriverParam(parm, "no_threads") == NULL && GetDriverParam(parm, "no_thread") == NULL && std::thread::hardware_concurrency() > 1;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue