6198 Let's EOL cachefs
[illumos-gate.git] / usr / src / lib / libnsl / common / common.c
blobea9779646bd346182d68100180b78233cc817063
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "mt.h"
30 #include <stdlib.h>
32 void *
33 thr_get_storage(pthread_key_t *keyp, size_t size, void (*destructor)(void *))
35 void *addr;
37 if (pthread_key_create_once_np(keyp, destructor) != 0)
38 return (NULL);
39 addr = pthread_getspecific(*keyp);
40 if (addr == NULL && size != 0) {
41 addr = calloc(1, size);
42 if (addr != NULL && pthread_setspecific(*keyp, addr) != 0) {
43 free(addr);
44 return (NULL);
48 return (addr);
52 * sig_mutex_lock() and sig_mutex_unlock() are the same
53 * as mutex_lock() and mutex_unlock() except that all
54 * signals are deferred while the lock is held. Likewise
55 * for sig_rw_rdlock(), sig_rw_wrlock() and sig_rw_unlock().
57 * _sigoff() and _sigon() are consolidation-private
58 * interfaces in libc that defer and enable signals.
59 * Calls to these can nest but must be balanced, so
60 * nested calls to these functions work properly.
63 void
64 sig_mutex_lock(mutex_t *mp)
66 _sigoff();
67 (void) mutex_lock(mp);
70 void
71 sig_mutex_unlock(mutex_t *mp)
73 (void) mutex_unlock(mp);
74 _sigon();
77 void
78 sig_rw_rdlock(rwlock_t *rwlp)
80 _sigoff();
81 (void) rw_rdlock(rwlp);
84 void
85 sig_rw_wrlock(rwlock_t *rwlp)
87 _sigoff();
88 (void) rw_wrlock(rwlp);
91 void
92 sig_rw_unlock(rwlock_t *rwlp)
94 (void) rw_unlock(rwlp);
95 _sigon();