4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
37 typedef void (*pfrv_t
)(void *);
46 _free_tsdbuf(void *ptr
)
54 for (i
= 0; i
< _T_NUM_ENTRIES
; i
++) {
55 if ((p
= loc
[i
].buf
) != NULL
) {
56 destructor
= loc
[i
].destructor
;
57 if (destructor
!= NULL
)
59 lfree(p
, loc
[i
].size
);
62 lfree(loc
, _T_NUM_ENTRIES
* sizeof (tsdent_t
));
67 tsdalloc(__tsd_item_t n
, size_t size
, pfrv_t destructor
)
69 static thread_key_t key
= THR_ONCE_KEY
;
74 if ((uint_t
)n
>= _T_NUM_ENTRIES
) {
79 if ((error
= thr_keycreate_once(&key
, _free_tsdbuf
)) != 0) {
84 if ((loc
= pthread_getspecific(key
)) != NULL
) {
85 if ((p
= loc
[n
].buf
) != NULL
)
88 /* allocate our array of pointers */
89 loc
= lmalloc(_T_NUM_ENTRIES
* sizeof (tsdent_t
));
92 if ((error
= thr_setspecific(key
, loc
)) != 0) {
93 lfree(loc
, _T_NUM_ENTRIES
* sizeof (tsdent_t
));
100 loc
[n
].buf
= p
= lmalloc(size
);
102 loc
[n
].destructor
= destructor
;