diff options
-rw-r--r-- | cmake/os/WindowsCache.cmake | 2 | ||||
-rw-r--r-- | config.h.cmake | 3 | ||||
-rw-r--r-- | configure.cmake | 2 | ||||
-rw-r--r-- | mysys/my_getncpus.c | 31 |
4 files changed, 37 insertions, 1 deletions
diff --git a/cmake/os/WindowsCache.cmake b/cmake/os/WindowsCache.cmake index 1cb6c81b627..1dbedfc24f2 100644 --- a/cmake/os/WindowsCache.cmake +++ b/cmake/os/WindowsCache.cmake @@ -127,6 +127,8 @@ SET(HAVE_PTHREAD_ATTR_GETSTACKSIZE CACHE INTERNAL "") SET(HAVE_PTHREAD_ATTR_SETSCOPE CACHE INTERNAL "") SET(HAVE_PTHREAD_ATTR_SETSTACKSIZE CACHE INTERNAL "") SET(HAVE_PTHREAD_CONDATTR_CREATE CACHE INTERNAL "") +SET(HAVE_PTHREAD_CONDATTR_SETCLOCK CACHE INTERNAL "") +SET(HAVE_PTHREAD_GETAFFINITY_NP CACHE INTERNAL "") SET(HAVE_PTHREAD_INIT CACHE INTERNAL "") SET(HAVE_PTHREAD_KEY_DELETE CACHE INTERNAL "") SET(HAVE_PTHREAD_RWLOCK_RDLOCK CACHE INTERNAL "") diff --git a/config.h.cmake b/config.h.cmake index 6e4af65c40e..fdaba640ad6 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -200,6 +200,9 @@ #cmakedefine HAVE_PTHREAD_ATTR_SETSCOPE 1 #cmakedefine HAVE_PTHREAD_ATTR_SETSTACKSIZE 1 #cmakedefine HAVE_PTHREAD_CONDATTR_CREATE 1 +#cmakedefine HAVE_PTHREAD_CONDATTR_SETCLOCK 1 +#cmakedefine HAVE_PTHREAD_GETAFFINITY_NP 1 +#cmakedefine HAVE_PTHREAD_KEY_DELETE 1 #cmakedefine HAVE_PTHREAD_KEY_DELETE 1 #cmakedefine HAVE_PTHREAD_KILL 1 #cmakedefine HAVE_PTHREAD_RWLOCK_RDLOCK 1 diff --git a/configure.cmake b/configure.cmake index f94fb3642a5..a85652a8345 100644 --- a/configure.cmake +++ b/configure.cmake @@ -375,6 +375,8 @@ CHECK_FUNCTION_EXISTS (pthread_attr_setscope HAVE_PTHREAD_ATTR_SETSCOPE) CHECK_FUNCTION_EXISTS (pthread_attr_getguardsize HAVE_PTHREAD_ATTR_GETGUARDSIZE) CHECK_FUNCTION_EXISTS (pthread_attr_setstacksize HAVE_PTHREAD_ATTR_SETSTACKSIZE) CHECK_FUNCTION_EXISTS (pthread_condattr_create HAVE_PTHREAD_CONDATTR_CREATE) +CHECK_FUNCTION_EXISTS (pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK) +CHECK_FUNCTION_EXISTS (pthread_getaffinity_np HAVE_PTHREAD_GETAFFINITY_NP) CHECK_FUNCTION_EXISTS (pthread_key_delete HAVE_PTHREAD_KEY_DELETE) CHECK_FUNCTION_EXISTS (pthread_rwlock_rdlock HAVE_PTHREAD_RWLOCK_RDLOCK) CHECK_FUNCTION_EXISTS (pthread_sigmask HAVE_PTHREAD_SIGMASK) diff --git a/mysys/my_getncpus.c b/mysys/my_getncpus.c index 38585161c22..0ee03631da8 100644 --- a/mysys/my_getncpus.c +++ b/mysys/my_getncpus.c @@ -21,10 +21,36 @@ #include <unistd.h> #endif +#if defined(__FreeBSD__) && defined(HAVE_PTHREAD_GETAFFINITY_NP) +#include <pthread_np.h> +#include <sys/cpuset.h> +#endif + static int ncpus=0; -int my_getncpus() +int my_getncpus(void) { +#if (defined(__linux__) || defined(__FreeBSD__)) && defined(HAVE_PTHREAD_GETAFFINITY_NP) + cpu_set_t set; + + if (!ncpus) + { + if (pthread_getaffinity_np(pthread_self(), sizeof(set), &set) == 0) + { + ncpus= CPU_COUNT(&set); + } + else + { +#ifdef _SC_NPROCESSORS_ONLN + ncpus= sysconf(_SC_NPROCESSORS_ONLN); +#else + ncpus= 2; +#endif + } + } + +#else /* __linux__ || FreeBSD && HAVE_PTHREAD_GETAFFINITY_NP */ + if (!ncpus) { #ifdef _SC_NPROCESSORS_ONLN @@ -46,5 +72,8 @@ int my_getncpus() ncpus= 2; #endif } + +#endif /* __linux__ || FreeBSD && HAVE_PTHREAD_GETAFFINITY_NP */ + return ncpus; } |