pthr_attr.c (0:68f95e015346) pthr_attr.c (1885:7bbaa5935f99)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
22/*
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident "%Z%%M% %I% %E% SMI"
28
29#include "lint.h"
30#include "thr_uberdata.h"
31#include <sched.h>
32
33/*
24 * Use is subject to license terms.
25 */
26
27#pragma ident "%Z%%M% %I% %E% SMI"
28
29#include "lint.h"
30#include "thr_uberdata.h"
31#include <sched.h>
32
33/*
34 * Default attribute object for pthread_create() with NULL attr pointer.
35 * Note that the 'guardsize' field is initialized on the first call.
36 */
37const thrattr_t *
38def_thrattr(void)
39{
40 static thrattr_t thrattr = {
41 0, /* stksize */
42 NULL, /* stkaddr */
43 PTHREAD_CREATE_JOINABLE, /* detachstate */
44 PTHREAD_CREATE_NONDAEMON_NP, /* daemonstate */
45 PTHREAD_SCOPE_PROCESS, /* scope */
46 0, /* prio */
47 SCHED_OTHER, /* policy */
48 PTHREAD_EXPLICIT_SCHED, /* inherit */
49 0 /* guardsize */
50 };
51 if (thrattr.guardsize == 0)
52 thrattr.guardsize = _sysconf(_SC_PAGESIZE);
53 return (&thrattr);
54}
55
56/*
34 * pthread_attr_init: allocates the attribute object and initializes it
35 * with the default values.
36 */
37#pragma weak pthread_attr_init = _pthread_attr_init
38int
39_pthread_attr_init(pthread_attr_t *attr)
40{
41 thrattr_t *ap;
42
43 if ((ap = lmalloc(sizeof (thrattr_t))) != NULL) {
57 * pthread_attr_init: allocates the attribute object and initializes it
58 * with the default values.
59 */
60#pragma weak pthread_attr_init = _pthread_attr_init
61int
62_pthread_attr_init(pthread_attr_t *attr)
63{
64 thrattr_t *ap;
65
66 if ((ap = lmalloc(sizeof (thrattr_t))) != NULL) {
44 if (_lpagesize == 0)
45 _lpagesize = _sysconf(_SC_PAGESIZE);
46 ap->stksize = 0;
47 ap->stkaddr = NULL;
48 ap->prio = 0;
49 ap->policy = SCHED_OTHER;
50 ap->inherit = PTHREAD_EXPLICIT_SCHED;
51 ap->detachstate = PTHREAD_CREATE_JOINABLE;
52 ap->scope = PTHREAD_SCOPE_PROCESS;
53 ap->guardsize = _lpagesize;
67 *ap = *def_thrattr();
54 attr->__pthread_attrp = ap;
55 return (0);
56 }
57 return (ENOMEM);
58}
59
60/*
61 * pthread_attr_destroy: frees the attribute object and invalidates it

--- 6 unchanged lines hidden (view full) ---

68 if (attr == NULL || attr->__pthread_attrp == NULL)
69 return (EINVAL);
70 lfree(attr->__pthread_attrp, sizeof (thrattr_t));
71 attr->__pthread_attrp = NULL;
72 return (0);
73}
74
75/*
68 attr->__pthread_attrp = ap;
69 return (0);
70 }
71 return (ENOMEM);
72}
73
74/*
75 * pthread_attr_destroy: frees the attribute object and invalidates it

--- 6 unchanged lines hidden (view full) ---

82 if (attr == NULL || attr->__pthread_attrp == NULL)
83 return (EINVAL);
84 lfree(attr->__pthread_attrp, sizeof (thrattr_t));
85 attr->__pthread_attrp = NULL;
86 return (0);
87}
88
89/*
90 * _pthread_attr_clone: make a copy of a pthread_attr_t.
91 * This is a consolidation-private interface, for librt.
92 */
93int
94_pthread_attr_clone(pthread_attr_t *attr, const pthread_attr_t *old_attr)
95{
96 thrattr_t *ap;
97 const thrattr_t *old_ap =
98 old_attr? old_attr->__pthread_attrp : def_thrattr();
99
100 if (old_ap == NULL)
101 return (EINVAL);
102 if ((ap = lmalloc(sizeof (thrattr_t))) == NULL)
103 return (ENOMEM);
104 *ap = *old_ap;
105 attr->__pthread_attrp = ap;
106 return (0);
107}
108
109/*
110 * _pthread_attr_equal: compare two pthread_attr_t's, return 1 if equal.
111 * A NULL pthread_attr_t pointer implies default attributes.
112 * This is a consolidation-private interface, for librt.
113 */
114int
115_pthread_attr_equal(const pthread_attr_t *attr1, const pthread_attr_t *attr2)
116{
117 const thrattr_t *ap1 = attr1? attr1->__pthread_attrp : def_thrattr();
118 const thrattr_t *ap2 = attr2? attr2->__pthread_attrp : def_thrattr();
119
120 if (ap1 == NULL || ap2 == NULL)
121 return (0);
122 return (ap1 == ap2 || _memcmp(ap1, ap2, sizeof (thrattr_t)) == 0);
123}
124
125/*
76 * pthread_attr_setstacksize: sets the user stack size, minimum should
77 * be PTHREAD_STACK_MIN (MINSTACK).
78 * This is equivalent to stksize argument in thr_create().
79 */
80#pragma weak pthread_attr_setstacksize = _pthread_attr_setstacksize
81int
82_pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
83{

--- 54 unchanged lines hidden (view full) ---

138 stackaddr != NULL) {
139 *stackaddr = ap->stkaddr;
140 return (0);
141 }
142 return (EINVAL);
143}
144
145/*
126 * pthread_attr_setstacksize: sets the user stack size, minimum should
127 * be PTHREAD_STACK_MIN (MINSTACK).
128 * This is equivalent to stksize argument in thr_create().
129 */
130#pragma weak pthread_attr_setstacksize = _pthread_attr_setstacksize
131int
132_pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
133{

--- 54 unchanged lines hidden (view full) ---

188 stackaddr != NULL) {
189 *stackaddr = ap->stkaddr;
190 return (0);
191 }
192 return (EINVAL);
193}
194
195/*
146 * pthread_attr_setdetachstate: sets the detach state to JOINABLE or
147 * DETACHED.
148 * This is equivalent to setting THR_DETACHED flag in thr_create().
196 * pthread_attr_setdetachstate: sets the detach state to DETACHED or JOINABLE.
197 * PTHREAD_CREATE_DETACHED is equivalent to thr_create(THR_DETACHED).
149 */
150#pragma weak pthread_attr_setdetachstate = _pthread_attr_setdetachstate
151int
152_pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
153{
154 thrattr_t *ap;
155
156 if (attr != NULL && (ap = attr->__pthread_attrp) != NULL &&

--- 18 unchanged lines hidden (view full) ---

175 detachstate != NULL) {
176 *detachstate = ap->detachstate;
177 return (0);
178 }
179 return (EINVAL);
180}
181
182/*
198 */
199#pragma weak pthread_attr_setdetachstate = _pthread_attr_setdetachstate
200int
201_pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
202{
203 thrattr_t *ap;
204
205 if (attr != NULL && (ap = attr->__pthread_attrp) != NULL &&

--- 18 unchanged lines hidden (view full) ---

224 detachstate != NULL) {
225 *detachstate = ap->detachstate;
226 return (0);
227 }
228 return (EINVAL);
229}
230
231/*
232 * pthread_attr_setdaemonstate_np: sets the daemon state to DAEMON or NONDAEMON.
233 * PTHREAD_CREATE_DAEMON is equivalent to thr_create(THR_DAEMON).
234 * For now, this is a consolidation-private interface for librt.
235 */
236int
237_pthread_attr_setdaemonstate_np(pthread_attr_t *attr, int daemonstate)
238{
239 thrattr_t *ap;
240
241 if (attr != NULL && (ap = attr->__pthread_attrp) != NULL &&
242 (daemonstate == PTHREAD_CREATE_DAEMON_NP ||
243 daemonstate == PTHREAD_CREATE_NONDAEMON_NP)) {
244 ap->daemonstate = daemonstate;
245 return (0);
246 }
247 return (EINVAL);
248}
249
250/*
251 * pthread_attr_getdaemonstate_np: gets the daemon state.
252 * For now, this is a consolidation-private interface for librt.
253 */
254int
255_pthread_attr_getdaemonstate_np(const pthread_attr_t *attr, int *daemonstate)
256{
257 thrattr_t *ap;
258
259 if (attr != NULL && (ap = attr->__pthread_attrp) != NULL &&
260 daemonstate != NULL) {
261 *daemonstate = ap->daemonstate;
262 return (0);
263 }
264 return (EINVAL);
265}
266
267/*
183 * pthread_attr_setscope: sets the scope to SYSTEM or PROCESS.
184 * This is equivalent to setting THR_BOUND flag in thr_create().
185 */
186#pragma weak pthread_attr_setscope = _pthread_attr_setscope
187int
188_pthread_attr_setscope(pthread_attr_t *attr, int scope)
189{
190 thrattr_t *ap;

--- 222 unchanged lines hidden ---
268 * pthread_attr_setscope: sets the scope to SYSTEM or PROCESS.
269 * This is equivalent to setting THR_BOUND flag in thr_create().
270 */
271#pragma weak pthread_attr_setscope = _pthread_attr_setscope
272int
273_pthread_attr_setscope(pthread_attr_t *attr, int scope)
274{
275 thrattr_t *ap;

--- 222 unchanged lines hidden ---