Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/os/refstr.c
+++ new/usr/src/uts/common/os/refstr.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 27 #include <sys/systm.h>
30 28 #include <sys/param.h>
31 29 #include <sys/atomic.h>
32 30 #include <sys/kmem.h>
33 31 #include <sys/refstr.h>
34 32 #include <sys/refstr_impl.h>
35 33
36 34 refstr_t *
37 35 refstr_alloc(const char *str)
38 36 {
39 37 refstr_t *rsp;
40 38 size_t size = sizeof (rsp->rs_size) + sizeof (rsp->rs_refcnt) +
41 39 strlen(str) + 1;
42 40
43 41 ASSERT(size <= UINT32_MAX);
44 42 rsp = kmem_alloc(size, KM_SLEEP);
45 43 rsp->rs_size = (uint32_t)size;
46 44 rsp->rs_refcnt = 1;
47 45 (void) strcpy(rsp->rs_string, str);
48 46 return (rsp);
49 47 }
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
50 48
51 49 const char *
52 50 refstr_value(refstr_t *rsp)
53 51 {
54 52 return (rsp != NULL ? (const char *)rsp->rs_string : NULL);
55 53 }
56 54
57 55 void
58 56 refstr_hold(refstr_t *rsp)
59 57 {
60 - atomic_add_32(&rsp->rs_refcnt, 1);
58 + atomic_inc_32(&rsp->rs_refcnt);
61 59 }
62 60
63 61 void
64 62 refstr_rele(refstr_t *rsp)
65 63 {
66 - if (atomic_add_32_nv(&rsp->rs_refcnt, -1) == 0)
64 + if (atomic_dec_32_nv(&rsp->rs_refcnt) == 0)
67 65 kmem_free(rsp, (size_t)rsp->rs_size);
68 66 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX