]>
Commit | Line | Data |
---|---|---|
61dd6208 | 1 | /* Set the default attributes to be used by pthread_create in the process. |
d614a753 | 2 | Copyright (C) 2013-2020 Free Software Foundation, Inc. |
61dd6208 SP |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
61dd6208 SP |
18 | |
19 | #include <errno.h> | |
20 | #include <stdlib.h> | |
21 | #include <pthreadP.h> | |
e781d7c5 | 22 | #include <string.h> |
59ff172f | 23 | |
61dd6208 SP |
24 | |
25 | int | |
26 | pthread_setattr_default_np (const pthread_attr_t *in) | |
27 | { | |
28 | const struct pthread_attr *real_in; | |
61dd6208 SP |
29 | int ret; |
30 | ||
61dd6208 SP |
31 | real_in = (struct pthread_attr *) in; |
32 | ||
33 | /* Catch invalid values. */ | |
34 | int policy = real_in->schedpolicy; | |
35 | ret = check_sched_policy_attr (policy); | |
36 | if (ret) | |
37 | return ret; | |
38 | ||
39 | const struct sched_param *param = &real_in->schedparam; | |
40 | if (param->sched_priority > 0) | |
41 | { | |
42 | ret = check_sched_priority_attr (param->sched_priority, policy); | |
43 | if (ret) | |
44 | return ret; | |
45 | } | |
46 | ||
61dd6208 SP |
47 | /* stacksize == 0 is fine. It means that we don't change the current |
48 | value. */ | |
49 | if (real_in->stacksize != 0) | |
50 | { | |
51 | ret = check_stacksize_attr (real_in->stacksize); | |
52 | if (ret) | |
53 | return ret; | |
54 | } | |
55 | ||
56 | /* Having a default stack address is wrong. */ | |
57 | if (real_in->flags & ATTR_FLAG_STACKADDR) | |
58 | return EINVAL; | |
59 | ||
7bf1094e FW |
60 | union pthread_attr_transparent temp; |
61 | ret = __pthread_attr_copy (&temp.external, in); | |
62 | if (ret != 0) | |
63 | return ret; | |
61dd6208 | 64 | |
7bf1094e | 65 | /* Now take the lock because we start accessing |
61dd6208 SP |
66 | __default_pthread_attr. */ |
67 | lll_lock (__default_pthread_attr_lock, LLL_PRIVATE); | |
68 | ||
7bf1094e FW |
69 | /* Preserve the previous stack size (see above). */ |
70 | if (temp.internal.stacksize == 0) | |
c2322a56 | 71 | temp.internal.stacksize = __default_pthread_attr.internal.stacksize; |
7bf1094e FW |
72 | |
73 | /* Destroy the old attribute structure because it will be | |
74 | overwritten. */ | |
c2322a56 | 75 | __pthread_attr_destroy (&__default_pthread_attr.external); |
61dd6208 | 76 | |
7bf1094e FW |
77 | /* __default_pthread_attr takes ownership, so do not free |
78 | attrs.internal after this point. */ | |
c2322a56 | 79 | __default_pthread_attr = temp; |
61dd6208 | 80 | |
61dd6208 SP |
81 | lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE); |
82 | return ret; | |
83 | } |