Revert "mips64: time64 for n32 ABI breaks a lot of tests, disable it for now"
[uclibc-ng.git] / libpthread / linuxthreads / attr.c
blob8465c234cbe615ad14331c09253ea7aefb4af52a
1 /* Linuxthreads - a simple clone()-based implementation of Posix */
2 /* threads for Linux. */
3 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
4 /* */
5 /* This program is free software; you can redistribute it and/or */
6 /* modify it under the terms of the GNU Library General Public License */
7 /* as published by the Free Software Foundation; either version 2 */
8 /* of the License, or (at your option) any later version. */
9 /* */
10 /* This program 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 */
13 /* GNU Library General Public License for more details. */
15 /* changed for uClibc */
16 #define __sched_get_priority_min sched_get_priority_min
17 #define __sched_get_priority_max sched_get_priority_max
19 /* Handling of thread attributes */
21 #include <errno.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <sys/param.h>
25 #include "pthread.h"
26 #include "internals.h"
28 libpthread_hidden_proto(pthread_attr_destroy)
29 libpthread_hidden_proto(pthread_attr_init)
30 libpthread_hidden_proto(pthread_attr_getdetachstate)
31 libpthread_hidden_proto(pthread_attr_setdetachstate)
32 libpthread_hidden_proto(pthread_attr_getinheritsched)
33 libpthread_hidden_proto(pthread_attr_setinheritsched)
34 libpthread_hidden_proto(pthread_attr_setschedparam)
35 libpthread_hidden_proto(pthread_attr_getschedparam)
36 libpthread_hidden_proto(pthread_attr_getschedpolicy)
37 libpthread_hidden_proto(pthread_attr_setschedpolicy)
38 libpthread_hidden_proto(pthread_attr_getscope)
39 libpthread_hidden_proto(pthread_attr_setscope)
41 /* NOTE: With uClibc I don't think we need this versioning stuff.
42 * Therefore, define the function pthread_attr_init() here using
43 * a strong symbol. */
45 /*int __pthread_attr_init_2_1(pthread_attr_t *attr)*/
46 int pthread_attr_init(pthread_attr_t *attr)
48 size_t ps = getpagesize ();
50 attr->__detachstate = PTHREAD_CREATE_JOINABLE;
51 attr->__schedpolicy = SCHED_OTHER;
52 attr->__schedparam.sched_priority = 0;
53 attr->__inheritsched = PTHREAD_EXPLICIT_SCHED;
54 attr->__scope = PTHREAD_SCOPE_SYSTEM;
55 attr->__guardsize = ps;
56 attr->__stackaddr = NULL;
57 attr->__stackaddr_set = 0;
58 attr->__stacksize = STACK_SIZE - ps;
59 return 0;
61 libpthread_hidden_def(pthread_attr_init)
63 /* uClibc: leave out this for now. */
64 #if defined DO_PTHREAD_VERSIONING_WITH_UCLIBC
65 #if defined __PIC__ && defined DO_VERSIONING
66 default_symbol_version (__pthread_attr_init_2_1, pthread_attr_init, GLIBC_2.1);
68 int __pthread_attr_init_2_0(pthread_attr_t *attr)
70 attr->__detachstate = PTHREAD_CREATE_JOINABLE;
71 attr->__schedpolicy = SCHED_OTHER;
72 attr->__schedparam.sched_priority = 0;
73 attr->__inheritsched = PTHREAD_EXPLICIT_SCHED;
74 attr->__scope = PTHREAD_SCOPE_SYSTEM;
75 return 0;
77 symbol_version (__pthread_attr_init_2_0, pthread_attr_init, GLIBC_2.0);
78 #else
79 strong_alias (__pthread_attr_init_2_1, pthread_attr_init)
80 #endif
81 #endif /* DO_PTHREAD_VERSIONING_WITH_UCLIBC */
83 int pthread_attr_destroy(pthread_attr_t *attr attribute_unused)
85 return 0;
87 libpthread_hidden_def(pthread_attr_destroy)
90 int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
92 if (detachstate < PTHREAD_CREATE_JOINABLE ||
93 detachstate > PTHREAD_CREATE_DETACHED)
94 return EINVAL;
95 attr->__detachstate = detachstate;
96 return 0;
98 libpthread_hidden_def(pthread_attr_setdetachstate)
100 int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
102 *detachstate = attr->__detachstate;
103 return 0;
105 libpthread_hidden_def(pthread_attr_getdetachstate)
107 int pthread_attr_setschedparam(pthread_attr_t *attr,
108 const struct sched_param *param)
110 int max_prio = __sched_get_priority_max(attr->__schedpolicy);
111 int min_prio = __sched_get_priority_min(attr->__schedpolicy);
113 if (param->sched_priority < min_prio || param->sched_priority > max_prio)
114 return EINVAL;
115 memcpy (&attr->__schedparam, param, sizeof (struct sched_param));
116 return 0;
118 libpthread_hidden_def(pthread_attr_setschedparam)
120 int pthread_attr_getschedparam(const pthread_attr_t *attr,
121 struct sched_param *param)
123 memcpy (param, &attr->__schedparam, sizeof (struct sched_param));
124 return 0;
126 libpthread_hidden_def(pthread_attr_getschedparam)
128 int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
130 if (policy != SCHED_OTHER && policy != SCHED_FIFO && policy != SCHED_RR)
131 return EINVAL;
132 attr->__schedpolicy = policy;
133 return 0;
135 libpthread_hidden_def(pthread_attr_setschedpolicy)
137 int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
139 *policy = attr->__schedpolicy;
140 return 0;
142 libpthread_hidden_def(pthread_attr_getschedpolicy)
144 int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit)
146 if (inherit != PTHREAD_INHERIT_SCHED && inherit != PTHREAD_EXPLICIT_SCHED)
147 return EINVAL;
148 attr->__inheritsched = inherit;
149 return 0;
151 libpthread_hidden_def(pthread_attr_setinheritsched)
153 int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inherit)
155 *inherit = attr->__inheritsched;
156 return 0;
158 libpthread_hidden_def(pthread_attr_getinheritsched)
160 int pthread_attr_setscope(pthread_attr_t *attr, int scope)
162 switch (scope) {
163 case PTHREAD_SCOPE_SYSTEM:
164 attr->__scope = scope;
165 return 0;
166 case PTHREAD_SCOPE_PROCESS:
167 return ENOTSUP;
168 default:
169 return EINVAL;
172 libpthread_hidden_def(pthread_attr_setscope)
174 int pthread_attr_getscope(const pthread_attr_t *attr, int *scope)
176 *scope = attr->__scope;
177 return 0;
179 libpthread_hidden_def(pthread_attr_getscope)
181 int __pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
183 size_t ps = getpagesize ();
185 /* First round up the guard size. */
186 guardsize = roundup (guardsize, ps);
188 /* The guard size must not be larger than the stack itself */
189 if (guardsize >= attr->__stacksize) return EINVAL;
191 attr->__guardsize = guardsize;
193 return 0;
195 weak_alias (__pthread_attr_setguardsize, pthread_attr_setguardsize)
197 int __pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize)
199 *guardsize = attr->__guardsize;
200 return 0;
202 weak_alias (__pthread_attr_getguardsize, pthread_attr_getguardsize)
204 #if 0 /* uClibc: deprecated stuff disabled */
205 int __pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
207 attr->__stackaddr = stackaddr;
208 attr->__stackaddr_set = 1;
209 return 0;
211 weak_alias (__pthread_attr_setstackaddr, pthread_attr_setstackaddr)
213 int __pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
215 /* XXX This function has a stupid definition. The standard specifies
216 no error value but what is if no stack address was set? We simply
217 return the value we have in the member. */
218 *stackaddr = attr->__stackaddr;
219 return 0;
221 weak_alias (__pthread_attr_getstackaddr, pthread_attr_getstackaddr)
222 #endif
224 int __pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
226 /* We don't accept value smaller than PTHREAD_STACK_MIN. */
227 if (stacksize < PTHREAD_STACK_MIN)
228 return EINVAL;
230 attr->__stacksize = stacksize;
231 return 0;
233 weak_alias (__pthread_attr_setstacksize, pthread_attr_setstacksize)
235 int __pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
237 *stacksize = attr->__stacksize;
238 return 0;
240 weak_alias (__pthread_attr_getstacksize, pthread_attr_getstacksize)