]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/pthread_attr_setaffinity.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / nptl / pthread_attr_setaffinity.c
CommitLineData
dff8da6b 1/* Copyright (C) 2003-2024 Free Software Foundation, Inc.
80f536db 2 This file is part of the GNU C Library.
80f536db
UD
3
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.
8
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.
13
14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
80f536db 17
80f536db 18#include <errno.h>
439ff07b 19#include <limits.h>
80f536db
UD
20#include <stdlib.h>
21#include <string.h>
22#include <pthreadP.h>
439ff07b 23#include <shlib-compat.h>
80f536db
UD
24
25
26int
1979819d
FW
27__pthread_attr_setaffinity_np (pthread_attr_t *attr, size_t cpusetsize,
28 const cpu_set_t *cpuset)
80f536db
UD
29{
30 struct pthread_attr *iattr;
31
80f536db
UD
32 iattr = (struct pthread_attr *) attr;
33
439ff07b 34 if (cpuset == NULL || cpusetsize == 0)
80f536db 35 {
7538d461
FW
36 if (iattr->extension != NULL)
37 {
38 free (iattr->extension->cpuset);
39 iattr->extension->cpuset = NULL;
40 iattr->extension->cpusetsize = 0;
41 }
80f536db 42 }
9ba96eda
UD
43 else
44 {
7538d461
FW
45 int ret = __pthread_attr_extension (iattr);
46 if (ret != 0)
47 return ret;
48
49 if (iattr->extension->cpusetsize != cpusetsize)
9ba96eda 50 {
7538d461 51 void *newp = realloc (iattr->extension->cpuset, cpusetsize);
439ff07b 52 if (newp == NULL)
9ba96eda 53 return ENOMEM;
439ff07b 54
7538d461
FW
55 iattr->extension->cpuset = newp;
56 iattr->extension->cpusetsize = cpusetsize;
9ba96eda 57 }
80f536db 58
7538d461 59 memcpy (iattr->extension->cpuset, cpuset, cpusetsize);
9ba96eda 60 }
80f536db
UD
61
62 return 0;
63}
1979819d
FW
64libc_hidden_def (__pthread_attr_setaffinity_np)
65versioned_symbol (libc, __pthread_attr_setaffinity_np,
66 pthread_attr_setaffinity_np, GLIBC_2_32);
439ff07b
UD
67
68
1979819d
FW
69#if SHLIB_COMPAT (libc, GLIBC_2_3_4, GLIBC_2_32)
70/* Compat symbol with the old libc version. */
71strong_alias (__pthread_attr_setaffinity_np, __pthread_attr_setaffinity_alias)
72compat_symbol (libc, __pthread_attr_setaffinity_alias,
73 pthread_attr_setaffinity_np, GLIBC_2_3_4);
74#endif
75
76#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
439ff07b 77int
63f78a3a 78__pthread_attr_setaffinity_old (pthread_attr_t *attr, cpu_set_t *cpuset)
439ff07b
UD
79{
80 /* The old interface by default assumed a 1024 processor bitmap. */
1979819d 81 return __pthread_attr_setaffinity_np (attr, 128, cpuset);
439ff07b 82}
1979819d 83compat_symbol (libc, __pthread_attr_setaffinity_old,
439ff07b
UD
84 pthread_attr_setaffinity_np, GLIBC_2_3_3);
85#endif