#define _GNU_SOURCE
#define ulong ulongxx
#include <sched.h>
#undef ulong
#include "thread_pool.h"
#if FLINT_USES_PTHREAD && defined(HAVE_PTHREAD_NP_H)
# include <pthread_np.h>
#endif
int thread_pool_set_affinity(thread_pool_t T, int * cpus, slong length)
{
#if FLINT_USES_CPUSET && FLINT_USES_PTHREAD
slong i;
int errorno;
cpu_set_t mask;
thread_pool_entry_struct * D;
if (length <= 0)
return 0;
D = T->tdata;
for (i = 0; i + 1 < length && i < T->length; i++)
{
CPU_ZERO(&mask);
CPU_SET(cpus[i + 1] % CPU_SETSIZE, &mask);
errorno = pthread_setaffinity_np(D[i].pth, sizeof(cpu_set_t), &mask);
if (errorno != 0)
return errorno;
}
CPU_ZERO(&mask);
CPU_SET(cpus[0] % CPU_SETSIZE, &mask);
errorno = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &mask);
if (errorno != 0)
return errorno;
#endif
return 0;
}