1 /* Deep copy of a pthread_attr_t object.
2 Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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 <https://www.gnu.org/licenses/>. */
24 __pthread_attr_copy (pthread_attr_t
*target
, const pthread_attr_t
*source
)
26 /* Avoid overwriting *TARGET until all allocations have
28 union pthread_attr_transparent temp
;
29 temp
.external
= *source
;
31 /* Force new allocation. This function has full ownership of temp. */
32 temp
.internal
.extension
= NULL
;
36 struct pthread_attr
*isource
= (struct pthread_attr
*) source
;
38 if (isource
->extension
!= NULL
)
40 /* Propagate affinity mask information. */
41 if (isource
->extension
->cpusetsize
> 0)
42 ret
= __pthread_attr_setaffinity_np (&temp
.external
,
43 isource
->extension
->cpusetsize
,
44 isource
->extension
->cpuset
);
46 /* Propagate the signal mask information. */
47 if (ret
== 0 && isource
->extension
->sigmask_set
)
48 ret
= __pthread_attr_setsigmask_internal ((pthread_attr_t
*) &temp
,
49 &isource
->extension
->sigmask
);
54 /* Deallocate because we have ownership. */
55 __pthread_attr_destroy (&temp
.external
);
59 /* Transfer ownership. *target is not assumed to have been
61 *target
= temp
.external
;
64 libc_hidden_def (__pthread_attr_copy
)