Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/sys/refcount.h
+++ new/usr/src/uts/common/fs/zfs/sys/refcount.h
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 (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 24 */
25 25
26 26 #ifndef _SYS_REFCOUNT_H
27 27 #define _SYS_REFCOUNT_H
28 28
29 29 #include <sys/inttypes.h>
30 30 #include <sys/list.h>
31 31 #include <sys/zfs_context.h>
32 32
33 33 #ifdef __cplusplus
34 34 extern "C" {
35 35 #endif
36 36
37 37 /*
38 38 * If the reference is held only by the calling function and not any
39 39 * particular object, use FTAG (which is a string) for the holder_tag.
40 40 * Otherwise, use the object that holds the reference.
41 41 */
42 42 #define FTAG ((char *)__func__)
43 43
44 44 #ifdef ZFS_DEBUG
45 45 typedef struct reference {
46 46 list_node_t ref_link;
47 47 void *ref_holder;
48 48 uint64_t ref_number;
49 49 uint8_t *ref_removed;
50 50 } reference_t;
51 51
52 52 typedef struct refcount {
53 53 kmutex_t rc_mtx;
54 54 boolean_t rc_tracked;
55 55 list_t rc_list;
56 56 list_t rc_removed;
57 57 uint64_t rc_count;
58 58 uint64_t rc_removed_count;
59 59 } refcount_t;
60 60
61 61 /* Note: refcount_t must be initialized with refcount_create[_untracked]() */
62 62
63 63 void refcount_create(refcount_t *rc);
64 64 void refcount_create_untracked(refcount_t *rc);
65 65 void refcount_destroy(refcount_t *rc);
66 66 void refcount_destroy_many(refcount_t *rc, uint64_t number);
67 67 int refcount_is_zero(refcount_t *rc);
68 68 int64_t refcount_count(refcount_t *rc);
69 69 int64_t refcount_add(refcount_t *rc, void *holder_tag);
70 70 int64_t refcount_remove(refcount_t *rc, void *holder_tag);
71 71 int64_t refcount_add_many(refcount_t *rc, uint64_t number, void *holder_tag);
72 72 int64_t refcount_remove_many(refcount_t *rc, uint64_t number, void *holder_tag);
73 73 void refcount_transfer(refcount_t *dst, refcount_t *src);
74 74
75 75 void refcount_init(void);
76 76 void refcount_fini(void);
77 77
78 78 #else /* ZFS_DEBUG */
79 79
↓ open down ↓ |
79 lines elided |
↑ open up ↑ |
80 80 typedef struct refcount {
81 81 uint64_t rc_count;
82 82 } refcount_t;
83 83
84 84 #define refcount_create(rc) ((rc)->rc_count = 0)
85 85 #define refcount_create_untracked(rc) ((rc)->rc_count = 0)
86 86 #define refcount_destroy(rc) ((rc)->rc_count = 0)
87 87 #define refcount_destroy_many(rc, number) ((rc)->rc_count = 0)
88 88 #define refcount_is_zero(rc) ((rc)->rc_count == 0)
89 89 #define refcount_count(rc) ((rc)->rc_count)
90 -#define refcount_add(rc, holder) atomic_add_64_nv(&(rc)->rc_count, 1)
91 -#define refcount_remove(rc, holder) atomic_add_64_nv(&(rc)->rc_count, -1)
90 +#define refcount_add(rc, holder) atomic_inc_64_nv(&(rc)->rc_count)
91 +#define refcount_remove(rc, holder) atomic_dec_64_nv(&(rc)->rc_count)
92 92 #define refcount_add_many(rc, number, holder) \
93 93 atomic_add_64_nv(&(rc)->rc_count, number)
94 94 #define refcount_remove_many(rc, number, holder) \
95 95 atomic_add_64_nv(&(rc)->rc_count, -number)
96 96 #define refcount_transfer(dst, src) { \
97 97 uint64_t __tmp = (src)->rc_count; \
98 98 atomic_add_64(&(src)->rc_count, -__tmp); \
99 99 atomic_add_64(&(dst)->rc_count, __tmp); \
100 100 }
101 101
102 102 #define refcount_init()
103 103 #define refcount_fini()
104 104
105 105 #endif /* ZFS_DEBUG */
106 106
107 107 #ifdef __cplusplus
108 108 }
109 109 #endif
110 110
111 111 #endif /* _SYS_REFCOUNT_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX