From c2bcdbebcb9d3a974cd171f69792c2e611343744 Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Wed, 6 Jul 2016 08:24:09 -0400 Subject: [PATCH] implement thread affinity for FreeBSD --- src/shared.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/shared.c b/src/shared.c index c2e7db874..e972b7d55 100644 --- a/src/shared.c +++ b/src/shared.c @@ -6,10 +6,15 @@ * License.....: MIT */ -#if defined(DARWIN) || defined(__FreeBSD__) +#ifdef DARWIN #include #endif +#ifdef __FreeBSD__ +#include +#include +#endif + #include #include @@ -4537,6 +4542,9 @@ void set_cpu_affinity (char *cpu_affinity) { #ifdef _WIN DWORD_PTR aff_mask = 0; + #elif __FreeBSD__ + cpuset_t cpuset; + CPU_ZERO (&cpuset); #elif _POSIX cpu_set_t cpuset; CPU_ZERO (&cpuset); @@ -4584,6 +4592,9 @@ void set_cpu_affinity (char *cpu_affinity) #ifdef _WIN SetProcessAffinityMask (GetCurrentProcess (), aff_mask); SetThreadAffinityMask (GetCurrentThread (), aff_mask); + #elif __FreeBSD__ + pthread_t thread = pthread_self (); + pthread_setaffinity_np (thread, sizeof (cpuset_t), &cpuset); #elif _POSIX pthread_t thread = pthread_self (); pthread_setaffinity_np (thread, sizeof (cpu_set_t), &cpuset);