Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/videolan/dav1d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/cpu.c
diff options
context:
space:
mode:
authorHenrik Gramner <gramner@twoorioles.com>2021-09-21 19:31:12 +0300
committerHenrik Gramner <gramner@twoorioles.com>2021-10-18 17:38:38 +0300
commit9b5149010527eb733b2dcfb568f80632b44cd287 (patch)
treed261e914762960dc185df10ac3c05528aa743ded /src/cpu.c
parentcff5ba694c572372e667f968fd806bb9363cc2df (diff)
Add support for auto thread selection on BSD
Diffstat (limited to 'src/cpu.c')
-rw-r--r--src/cpu.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/cpu.c b/src/cpu.c
index 0aa9024..c003011 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -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;