MINOR: threads: Implement thread_cpus_enabled() for FreeBSD.

Use cpuset_getaffinity() to implement thread_cpus_enabled() on FreeBSD, so
that we can know the number of CPUs available, and automatically launch as
much threads if nbthread isn't specified.
diff --git a/src/hathreads.c b/src/hathreads.c
index 1826f92..686edca 100644
--- a/src/hathreads.c
+++ b/src/hathreads.c
@@ -19,6 +19,10 @@
 #include <sched.h>
 #endif
 
+#ifdef __FreeBSD__
+#include <sys/cpuset.h>
+#endif
+
 #include <common/cfgparse.h>
 #include <common/hathreads.h>
 #include <common/standard.h>
@@ -122,6 +126,11 @@
 
 	if (sched_getaffinity(0, sizeof(mask), &mask) == 0)
 		ret = CPU_COUNT(&mask);
+#elif defined(__FreeBSD__) && defined(USE_CPU_AFFINITY)
+	cpuset_t cpuset;
+	if (cpuset_getaffinity(CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1,
+	    sizeof(cpuset), &cpuset) == 0)
+		ret = CPU_COUNT(&cpuset);
 #endif
 #endif
 	ret = MAX(ret, 1);