Back to index

glibc  2.9
pthread_attr_getaffinity.c
Go to the documentation of this file.
00001 /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <assert.h>
00021 #include <errno.h>
00022 #include <pthreadP.h>
00023 #include <string.h>
00024 #include <sysdep.h>
00025 #include <sys/types.h>
00026 #include <shlib-compat.h>
00027 
00028 
00029 int
00030 __pthread_attr_getaffinity_new (const pthread_attr_t *attr, size_t cpusetsize,
00031                             cpu_set_t *cpuset)
00032 {
00033   const struct pthread_attr *iattr;
00034 
00035   assert (sizeof (*attr) >= sizeof (struct pthread_attr));
00036   iattr = (const struct pthread_attr *) attr;
00037 
00038   if (iattr->cpuset != NULL)
00039     {
00040       /* Check whether there are any bits set beyond the limits
00041         the user requested.  */
00042       for (size_t cnt = cpusetsize; cnt < iattr->cpusetsize; ++cnt)
00043        if (((char *) iattr->cpuset)[cnt] != 0)
00044          return EINVAL;
00045 
00046       void *p = mempcpy (cpuset, iattr->cpuset, iattr->cpusetsize);
00047       if (cpusetsize > iattr->cpusetsize)
00048        memset (p, '\0', cpusetsize - iattr->cpusetsize);
00049     }
00050   else
00051     /* We have no information.  */
00052     memset (cpuset, -1, cpusetsize);
00053 
00054   return 0;
00055 }
00056 versioned_symbol (libpthread, __pthread_attr_getaffinity_new,
00057                 pthread_attr_getaffinity_np, GLIBC_2_3_4);
00058 
00059 
00060 #if SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
00061 int
00062 __pthread_attr_getaffinity_old (const pthread_attr_t *attr, cpu_set_t *cpuset)
00063 {
00064   /* The old interface by default assumed a 1024 processor bitmap.  */
00065   return __pthread_attr_getaffinity_new (attr, 128, cpuset);
00066 }
00067 compat_symbol (libpthread, __pthread_attr_getaffinity_old,
00068               pthread_attr_getaffinity_np, GLIBC_2_3_3);
00069 #endif