1 /* Copyright (C) 2003-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
23 #include <shlib-compat.h>
27 __pthread_attr_setaffinity_np (pthread_attr_t
*attr
, size_t cpusetsize
,
28 const cpu_set_t
*cpuset
)
30 struct pthread_attr
*iattr
;
32 iattr
= (struct pthread_attr
*) attr
;
34 if (cpuset
== NULL
|| cpusetsize
== 0)
36 if (iattr
->extension
!= NULL
)
38 free (iattr
->extension
->cpuset
);
39 iattr
->extension
->cpuset
= NULL
;
40 iattr
->extension
->cpusetsize
= 0;
45 int ret
= __pthread_attr_extension (iattr
);
49 if (iattr
->extension
->cpusetsize
!= cpusetsize
)
51 void *newp
= realloc (iattr
->extension
->cpuset
, cpusetsize
);
55 iattr
->extension
->cpuset
= newp
;
56 iattr
->extension
->cpusetsize
= cpusetsize
;
59 memcpy (iattr
->extension
->cpuset
, cpuset
, cpusetsize
);
64 libc_hidden_def (__pthread_attr_setaffinity_np
)
65 versioned_symbol (libc
, __pthread_attr_setaffinity_np
,
66 pthread_attr_setaffinity_np
, GLIBC_2_32
);
69 #if SHLIB_COMPAT (libc, GLIBC_2_3_4, GLIBC_2_32)
70 /* Compat symbol with the old libc version. */
71 strong_alias (__pthread_attr_setaffinity_np
, __pthread_attr_setaffinity_alias
)
72 compat_symbol (libc
, __pthread_attr_setaffinity_alias
,
73 pthread_attr_setaffinity_np
, GLIBC_2_3_4
);
76 #if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
78 __pthread_attr_setaffinity_old (pthread_attr_t
*attr
, cpu_set_t
*cpuset
)
80 /* The old interface by default assumed a 1024 processor bitmap. */
81 return __pthread_attr_setaffinity_np (attr
, 128, cpuset
);
83 compat_symbol (libc
, __pthread_attr_setaffinity_old
,
84 pthread_attr_setaffinity_np
, GLIBC_2_3_3
);