server: Use kernel support for thread affinity when available.
diff --git a/configure b/configure
index ceb6e20..d05447a 100755
--- a/configure
+++ b/configure
@@ -12127,6 +12127,7 @@
pwrite \
readdir \
readlink \
+ sched_setaffinity \
sched_yield \
select \
setproctitle \
diff --git a/configure.ac b/configure.ac
index d489f00..27ae652 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1692,6 +1692,7 @@
pwrite \
readdir \
readlink \
+ sched_setaffinity \
sched_yield \
select \
setproctitle \
diff --git a/include/config.h.in b/include/config.h.in
index d4bbce6..0be8f4d 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -645,6 +645,9 @@
/* Define to 1 if you have the <sched.h> header file. */
#undef HAVE_SCHED_H
+/* Define to 1 if you have the `sched_setaffinity' function. */
+#undef HAVE_SCHED_SETAFFINITY
+
/* Define to 1 if you have the `sched_yield' function. */
#undef HAVE_SCHED_YIELD
diff --git a/server/thread.c b/server/thread.c
index 8b367ca..211cefe 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -35,6 +35,9 @@
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
+#ifdef HAVE_SCHED_H
+#include <sched.h>
+#endif
#include "ntstatus.h"
#define WIN32_NO_STATUS
@@ -406,7 +409,26 @@
void set_thread_affinity( struct thread *thread, affinity_t affinity )
{
+#ifdef HAVE_SCHED_SETAFFINITY
+ if (thread->unix_pid != -1)
+ {
+ cpu_set_t set;
+ int i;
+ affinity_t mask;
+
+ CPU_ZERO( &set );
+ for (i = 0, mask = 1; mask; i++, mask <<= 1)
+ if (affinity & mask) CPU_SET( i, &set );
+
+ if (!sched_setaffinity( thread->unix_pid, sizeof(set), &set ))
+ thread->affinity = affinity;
+ else
+ file_set_error();
+ }
+ else set_error( STATUS_ACCESS_DENIED );
+#else
thread->affinity = affinity;
+#endif
}
#define THREAD_PRIORITY_REALTIME_HIGHEST 6