1 /* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
27 /* Defined in pthread_setaffinity.c. */
28 extern size_t __kernel_cpumask_size attribute_hidden;
29 extern int __determine_cpumask_size (pid_t tid);
30 libpthread_hidden_proto(__determine_cpumask_size)
33 pthread_attr_setaffinity_np (pthread_attr_t *attr, size_t cpusetsize,
34 const cpu_set_t *cpuset)
36 struct pthread_attr *iattr;
38 assert (sizeof (*attr) >= sizeof (struct pthread_attr));
39 iattr = (struct pthread_attr *) attr;
41 if (cpuset == NULL || cpusetsize == 0)
45 iattr->cpusetsize = 0;
49 if (__kernel_cpumask_size == 0)
51 int res = __determine_cpumask_size (THREAD_SELF->tid);
53 /* Some serious problem. */
57 /* Check whether the new bitmask has any bit set beyond the
58 last one the kernel accepts. */
60 for (cnt = __kernel_cpumask_size; cnt < cpusetsize; ++cnt)
61 if (((char *) cpuset)[cnt] != '\0')
62 /* Found a nonzero byte. This means the user request cannot be
66 if (iattr->cpusetsize != cpusetsize)
68 void *newp = (cpu_set_t *) realloc (iattr->cpuset, cpusetsize);
73 iattr->cpusetsize = cpusetsize;
76 memcpy (iattr->cpuset, cpuset, cpusetsize);