diff options
author | Michael Lutz <michi@icosahedron.de> | 2019-03-17 15:14:17 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-04-06 11:27:39 +0200 |
commit | 967b27a2c12953da3584f4eaade37f94effc007a (patch) | |
tree | ea2daf0e2abb3a861a467575636353f3d183a75e /src | |
parent | ae748166d06e756a0a6abab582dc341494a9b2da (diff) | |
download | openttd-967b27a2c12953da3584f4eaade37f94effc007a.tar.xz |
Codechange: C++11 STL has a function for getting the number of CPU cores.
Diffstat (limited to 'src')
-rw-r--r-- | src/os/macosx/macos.mm | 17 | ||||
-rw-r--r-- | src/os/os2/os2.cpp | 5 | ||||
-rw-r--r-- | src/os/unix/unix.cpp | 29 | ||||
-rw-r--r-- | src/os/windows/win32.cpp | 8 | ||||
-rw-r--r-- | src/thread.h | 6 | ||||
-rw-r--r-- | src/video/win32_v.cpp | 2 |
6 files changed, 1 insertions, 66 deletions
diff --git a/src/os/macosx/macos.mm b/src/os/macosx/macos.mm index 7fb71fe9e..ae9d86ee8 100644 --- a/src/os/macosx/macos.mm +++ b/src/os/macosx/macos.mm @@ -206,23 +206,6 @@ bool GetClipboardContents(char *buffer, const char *last) } #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. * @param name Name of the font. diff --git a/src/os/os2/os2.cpp b/src/os/os2/os2.cpp index b62e83e5e..70c75a410 100644 --- a/src/os/os2/os2.cpp +++ b/src/os/os2/os2.cpp @@ -208,11 +208,6 @@ bool GetClipboardContents(char *buffer, const char *last) const char *FS2OTTD(const char *name) {return name;} const char *OTTD2FS(const char *name) {return name;} -uint GetCPUCoreCount() -{ - return 1; -} - void OSOpenBrowser(const char *url) { // stub only diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp index e20a6c1b5..aa63019f6 100644 --- a/src/os/unix/unix.cpp +++ b/src/os/unix/unix.cpp @@ -274,35 +274,6 @@ bool GetClipboardContents(char *buffer, const char *last) #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) { pid_t child_pid = fork(); diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 9847de567..d2cc434a2 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -725,14 +725,6 @@ const char *GetCurrentLocale(const char *) return retbuf; } -uint GetCPUCoreCount() -{ - SYSTEM_INFO info; - - GetSystemInfo(&info); - return info.dwNumberOfProcessors; -} - static WCHAR _cur_iso_locale[16] = L""; diff --git a/src/thread.h b/src/thread.h index cd2608221..53548cc06 100644 --- a/src/thread.h +++ b/src/thread.h @@ -30,12 +30,6 @@ inline void CSleep(int 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. * @param name Name to set for the thread.. */ diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 5aec329b2..382c0d8fc 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -1149,7 +1149,7 @@ const char *VideoDriver_Win32::Start(const char * const *parm) 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; } |