Back to index

glibc  2.9
Functions | Variables
pthread_setaffinity.c File Reference
#include <alloca.h>
#include <errno.h>
#include <pthreadP.h>
#include <sysdep.h>
#include <sys/types.h>
#include <shlib-compat.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


int __determine_cpumask_size (pid_t tid)
int __pthread_setaffinity_new (pthread_t th, size_t cpusetsize, const cpu_set_t *cpuset)
 versioned_symbol (libpthread, __pthread_setaffinity_new, pthread_setaffinity_np, GLIBC_2_3_4)


size_t __kernel_cpumask_size attribute_hidden

Function Documentation

Definition at line 34 of file pthread_setaffinity.c.

  int res;

  size_t psize = 128;
  void *p = alloca (psize);

  while (res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, tid, psize, p),
        INTERNAL_SYSCALL_ERROR_P (res, err)
        && INTERNAL_SYSCALL_ERRNO (res, err) == EINVAL)
    p = extend_alloca (p, psize, 2 * psize);

  if (res == 0 || INTERNAL_SYSCALL_ERROR_P (res, err))
    return INTERNAL_SYSCALL_ERRNO (res, err);

  __kernel_cpumask_size = res;

  return 0;

Here is the call graph for this function:

Here is the caller graph for this function:

int __pthread_setaffinity_new ( pthread_t  th,
size_t  cpusetsize,
const cpu_set_t *  cpuset 

Definition at line 57 of file pthread_setaffinity.c.

  const struct pthread *pd = (const struct pthread *) th;

  int res;

  if (__builtin_expect (__kernel_cpumask_size == 0, 0))
      res = __determine_cpumask_size (pd->tid);
      if (res != 0)
       return res;

  /* We now know the size of the kernel cpumask_t.  Make sure the user
     does not request to set a bit beyond that.  */
  for (size_t cnt = __kernel_cpumask_size; cnt < cpusetsize; ++cnt)
    if (((char *) cpuset)[cnt] != '\0')
      /* Found a nonzero byte.  This means the user request cannot be
        fulfilled.  */
      return EINVAL;

  res = INTERNAL_SYSCALL (sched_setaffinity, err, 3, pd->tid, cpusetsize,

  if (!INTERNAL_SYSCALL_ERROR_P (res, err))

  return (INTERNAL_SYSCALL_ERROR_P (res, err)
         ? INTERNAL_SYSCALL_ERRNO (res, err)
         : 0);

Here is the call graph for this function:

versioned_symbol ( libpthread  ,
__pthread_setaffinity_new  ,
pthread_setaffinity_np  ,

Variable Documentation

size_t __kernel_cpumask_size attribute_hidden

Definition at line 28 of file pthread_setaffinity.c.