MINOR: threads: Add thread-map config parameter in the global section

By default, no affinity is set for threads. To bind threads on CPU, you must
define a "thread-map" in the global section. The format is the same than the
"cpu-map" parameter, with a small difference. The process number must be
defined, with the same format than cpu-map ("all", "even", "odd" or a number
between 1 and 31/63).

A thread will be bound on the intersection of its mapping and the one of the
process on which it is attached. If the intersection is null, no specific bind
will be set for the thread.
diff --git a/src/haproxy.c b/src/haproxy.c
index 30ac157..f4353e1 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2814,6 +2814,15 @@
 		for (i = 0; i < global.nbthread; i++) {
 			tids[i] = i;
 			pthread_create(&threads[i], NULL, &run_thread_poll_loop, &tids[i]);
+#ifdef USE_CPU_AFFINITY
+			if (global.cpu_map[relative_pid-1])
+				global.thread_map[relative_pid-1][i] &= global.cpu_map[relative_pid-1];
+
+			if (i < LONGBITS &&       /* only the first 32/64 threads may be pinned */
+			    global.thread_map[relative_pid-1][i]) /* only do this if the thread has a THREAD map */
+				pthread_setaffinity_np(threads[i],
+						       sizeof(unsigned long), (void *)&global.thread_map[relative_pid-1][i]);
+#endif
 		}
 		for (i = 0; i < global.nbthread; i++)
 			pthread_join(threads[i], NULL);
@@ -2830,6 +2839,17 @@
 	else {
 		tid = 0;
 
+#ifdef USE_THREAD
+#ifdef USE_CPU_AFFINITY
+		if (global.cpu_map[relative_pid-1])
+			global.thread_map[relative_pid-1][tid] &= global.cpu_map[relative_pid-1];
+
+		if (global.thread_map[relative_pid-1][tid]) /* only do this if the thread has a THREAD map */
+			pthread_setaffinity_np(pthread_self(),
+					       sizeof(unsigned long), (void *)&global.thread_map[relative_pid-1][tid]);
+#endif
+#endif
+
 		if (global.mode & MODE_MWORKER)
 			mworker_pipe_register(mworker_pipe);