common.c (7c478bd9) common.c (61961e0f)
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.
8 *

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

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 */
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.
8 *

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

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 */
22
22/*
23/*
23 * Copyright 1993-2003 Sun Microsystems, Inc. All rights reserved.
24 * Copyright 2005 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 "mt.h"
30#include <stdlib.h>
31
32void *
33thr_get_storage(pthread_key_t *keyp, size_t size, void (*destructor)(void *))
34{
35 extern mutex_t tsd_lock;
36 pthread_key_t key;
37 void *addr;
38
39 if ((key = *keyp) == 0) {
25 * Use is subject to license terms.
26 */
27
28#pragma ident "%Z%%M% %I% %E% SMI"
29
30#include "mt.h"
31#include <stdlib.h>
32
33void *
34thr_get_storage(pthread_key_t *keyp, size_t size, void (*destructor)(void *))
35{
36 extern mutex_t tsd_lock;
37 pthread_key_t key;
38 void *addr;
39
40 if ((key = *keyp) == 0) {
40 mutex_lock(&tsd_lock);
41 (void) mutex_lock(&tsd_lock);
41 if ((key = *keyp) == 0) {
42 if (pthread_key_create(keyp, destructor) != 0) {
42 if ((key = *keyp) == 0) {
43 if (pthread_key_create(keyp, destructor) != 0) {
43 mutex_unlock(&tsd_lock);
44 (void) mutex_unlock(&tsd_lock);
44 return (NULL);
45 }
46 key = *keyp;
47 }
45 return (NULL);
46 }
47 key = *keyp;
48 }
48 mutex_unlock(&tsd_lock);
49 (void) mutex_unlock(&tsd_lock);
49 }
50
51 addr = pthread_getspecific(key);
52 if (addr == NULL && size != 0) {
53 addr = calloc(1, size);
54 if (addr != NULL && pthread_setspecific(key, addr) != 0) {
55 free(addr);
56 return (NULL);

--- 52 unchanged lines hidden ---
50 }
51
52 addr = pthread_getspecific(key);
53 if (addr == NULL && size != 0) {
54 addr = calloc(1, size);
55 if (addr != NULL && pthread_setspecific(key, addr) != 0) {
56 free(addr);
57 return (NULL);

--- 52 unchanged lines hidden ---