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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include <shlib-compat.h>
29 /* Defined in pthread_setaffinity.c. */
30 extern size_t __kernel_cpumask_size attribute_hidden
;
31 extern int __determine_cpumask_size (pid_t tid
);
35 __pthread_attr_setaffinity_new (pthread_attr_t
*attr
, size_t cpusetsize
,
36 const cpu_set_t
*cpuset
)
38 struct pthread_attr
*iattr
;
40 assert (sizeof (*attr
) >= sizeof (struct pthread_attr
));
41 iattr
= (struct pthread_attr
*) attr
;
43 if (cpuset
== NULL
|| cpusetsize
== 0)
47 iattr
->cpusetsize
= 0;
51 if (__kernel_cpumask_size
== 0)
53 int res
= __determine_cpumask_size (THREAD_SELF
->tid
);
55 /* Some serious problem. */
59 /* Check whether the new bitmask has any bit set beyond the
60 last one the kernel accepts. */
61 for (size_t cnt
= __kernel_cpumask_size
; cnt
< cpusetsize
; ++cnt
)
62 if (((char *) cpuset
)[cnt
] != '\0')
63 /* Found a nonzero byte. This means the user request cannot be
67 if (iattr
->cpusetsize
!= cpusetsize
)
69 void *newp
= (cpu_set_t
*) realloc (iattr
->cpuset
, cpusetsize
);
74 iattr
->cpusetsize
= cpusetsize
;
77 memcpy (iattr
->cpuset
, cpuset
, cpusetsize
);
82 versioned_symbol (libpthread
, __pthread_attr_setaffinity_new
,
83 pthread_attr_setaffinity_np
, GLIBC_2_3_4
);
86 #if SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
88 __pthread_attr_setaffinity_old (pthread_attr_t
*attr
, cpu_set_t
*cpuset
)
90 /* The old interface by default assumed a 1024 processor bitmap. */
91 return __pthread_attr_setaffinity_new (attr
, 128, cpuset
);
93 compat_symbol (libpthread
, __pthread_attr_setaffinity_old
,
94 pthread_attr_setaffinity_np
, GLIBC_2_3_3
);