diff options
author | Henrik Gramner <gramner@twoorioles.com> | 2021-09-21 19:31:12 +0300 |
---|---|---|
committer | Henrik Gramner <gramner@twoorioles.com> | 2021-10-18 17:38:38 +0300 |
commit | 9b5149010527eb733b2dcfb568f80632b44cd287 (patch) | |
tree | d261e914762960dc185df10ac3c05528aa743ded /src/cpu.c | |
parent | cff5ba694c572372e667f968fd806bb9363cc2df (diff) |
Add support for auto thread selection on BSD
Diffstat (limited to 'src/cpu.c')
-rw-r--r-- | src/cpu.c | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -33,12 +33,19 @@ #ifdef _WIN32 #include <windows.h> -#elif defined(__linux__) -#include <sched.h> -#include <unistd.h> #elif defined(__APPLE__) #include <sys/sysctl.h> #include <sys/types.h> +#else +#include <pthread.h> +#include <unistd.h> +#endif + +#if defined(__DragonFly__) || defined(__FreeBSD__) +#include <pthread_np.h> +#endif +#if defined(__FreeBSD__) +#define cpu_set_t cpuset_t #endif static unsigned flags = 0; @@ -88,19 +95,17 @@ COLD int dav1d_num_logical_processors(Dav1dContext *const c) { GetNativeSystemInfo(&system_info); return system_info.dwNumberOfProcessors; #endif -#elif defined(__linux__) -#ifdef CPU_COUNT +#elif (defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__)) && defined(CPU_COUNT) cpu_set_t affinity; - if (!sched_getaffinity(0, sizeof(affinity), &affinity)) + if (!pthread_getaffinity_np(pthread_self(), sizeof(affinity), &affinity)) return CPU_COUNT(&affinity); -#else - return (int)sysconf(_SC_NPROCESSORS_ONLN); -#endif #elif defined(__APPLE__) int num_processors; size_t length = sizeof(num_processors); if (!sysctlbyname("hw.logicalcpu", &num_processors, &length, NULL, 0)) return num_processors; +#elif defined(_SC_NPROCESSORS_ONLN) + return (int)sysconf(_SC_NPROCESSORS_ONLN); #endif dav1d_log(c, "Unable to detect thread count, defaulting to single-threaded mode\n"); return 1; |