Back to index

glibc  2.9
Functions | Variables
pthread_attr_setaffinity.c File Reference
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <pthreadP.h>
#include <shlib-compat.h>

Go to the source code of this file.

Functions

int __determine_cpumask_size (pid_t tid)
int __pthread_attr_setaffinity_new (pthread_attr_t *attr, size_t cpusetsize, const cpu_set_t *cpuset)
 versioned_symbol (libpthread, __pthread_attr_setaffinity_new, pthread_attr_setaffinity_np, GLIBC_2_3_4)

Variables

size_t __kernel_cpumask_size attribute_hidden

Function Documentation

Definition at line 34 of file pthread_setaffinity.c.

{
  INTERNAL_SYSCALL_DECL (err);
  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_attr_setaffinity_new ( pthread_attr_t attr,
size_t  cpusetsize,
const cpu_set_t *  cpuset 
)

Definition at line 35 of file pthread_attr_setaffinity.c.

{
  struct pthread_attr *iattr;

  assert (sizeof (*attr) >= sizeof (struct pthread_attr));
  iattr = (struct pthread_attr *) attr;

  if (cpuset == NULL || cpusetsize == 0)
    {
      free (iattr->cpuset);
      iattr->cpuset = NULL;
      iattr->cpusetsize = 0;
    }
  else
    {
      if (__kernel_cpumask_size == 0)
       {
         int res = __determine_cpumask_size (THREAD_SELF->tid);
         if (res != 0)
           /* Some serious problem.  */
           return res;
       }

      /* Check whether the new bitmask has any bit set beyond the
        last one the kernel accepts.  */
      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;

      if (iattr->cpusetsize != cpusetsize)
       {
         void *newp = (cpu_set_t *) realloc (iattr->cpuset, cpusetsize);
         if (newp == NULL)
           return ENOMEM;

         iattr->cpuset = newp;
         iattr->cpusetsize = cpusetsize;
       }

      memcpy (iattr->cpuset, cpuset, cpusetsize);
    }

  return 0;
}

Here is the call graph for this function:

versioned_symbol ( libpthread  ,
__pthread_attr_setaffinity_new  ,
pthread_attr_setaffinity_np  ,
GLIBC_2_3_4   
)

Variable Documentation

size_t __kernel_cpumask_size attribute_hidden

Definition at line 25 of file init-first.c.