Print this page
5042 stop using deprecated atomic functions
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/bitmap.h
+++ new/usr/src/uts/common/sys/bitmap.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 /*
23 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 28 * Copyright (c) 2014 by Delphix. All rights reserved.
29 29 */
30 30
31 31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
32 32 /* All Rights Reserved */
33 33
34 34
35 35 #ifndef _SYS_BITMAP_H
36 36 #define _SYS_BITMAP_H
37 37
38 38 #ifdef __cplusplus
39 39 extern "C" {
40 40 #endif
41 41
42 42 #include <sys/feature_tests.h>
43 43 #if defined(__GNUC__) && defined(_ASM_INLINES) && \
44 44 (defined(__i386) || defined(__amd64))
45 45 #include <asm/bitmap.h>
46 46 #endif
47 47
48 48 /*
49 49 * Operations on bitmaps of arbitrary size
50 50 * A bitmap is a vector of 1 or more ulong_t's.
51 51 * The user of the package is responsible for range checks and keeping
52 52 * track of sizes.
53 53 */
54 54
55 55 #ifdef _LP64
56 56 #define BT_ULSHIFT 6 /* log base 2 of BT_NBIPUL, to extract word index */
57 57 #define BT_ULSHIFT32 5 /* log base 2 of BT_NBIPUL, to extract word index */
58 58 #else
59 59 #define BT_ULSHIFT 5 /* log base 2 of BT_NBIPUL, to extract word index */
60 60 #endif
61 61
62 62 #define BT_NBIPUL (1 << BT_ULSHIFT) /* n bits per ulong_t */
63 63 #define BT_ULMASK (BT_NBIPUL - 1) /* to extract bit index */
64 64
65 65 #ifdef _LP64
66 66 #define BT_NBIPUL32 (1 << BT_ULSHIFT32) /* n bits per ulong_t */
67 67 #define BT_ULMASK32 (BT_NBIPUL32 - 1) /* to extract bit index */
68 68 #define BT_ULMAXMASK 0xffffffffffffffff /* used by bt_getlowbit */
69 69 #else
70 70 #define BT_ULMAXMASK 0xffffffff
71 71 #endif
72 72
73 73 /*
74 74 * bitmap is a ulong_t *, bitindex an index_t
75 75 *
76 76 * The macros BT_WIM and BT_BIW internal; there is no need
77 77 * for users of this package to use them.
78 78 */
79 79
80 80 /*
81 81 * word in map
82 82 */
83 83 #define BT_WIM(bitmap, bitindex) \
84 84 ((bitmap)[(bitindex) >> BT_ULSHIFT])
85 85 /*
86 86 * bit in word
87 87 */
88 88 #define BT_BIW(bitindex) \
89 89 (1UL << ((bitindex) & BT_ULMASK))
90 90
91 91 #ifdef _LP64
92 92 #define BT_WIM32(bitmap, bitindex) \
93 93 ((bitmap)[(bitindex) >> BT_ULSHIFT32])
94 94
95 95 #define BT_BIW32(bitindex) \
96 96 (1UL << ((bitindex) & BT_ULMASK32))
97 97 #endif
98 98
99 99 /*
100 100 * These are public macros
101 101 *
102 102 * BT_BITOUL == n bits to n ulong_t's
103 103 */
104 104 #define BT_BITOUL(nbits) \
105 105 (((nbits) + BT_NBIPUL - 1l) / BT_NBIPUL)
106 106 #define BT_SIZEOFMAP(nbits) \
107 107 (BT_BITOUL(nbits) * sizeof (ulong_t))
108 108 #define BT_TEST(bitmap, bitindex) \
109 109 ((BT_WIM((bitmap), (bitindex)) & BT_BIW(bitindex)) ? 1 : 0)
110 110 #define BT_SET(bitmap, bitindex) \
111 111 { BT_WIM((bitmap), (bitindex)) |= BT_BIW(bitindex); }
112 112 #define BT_CLEAR(bitmap, bitindex) \
113 113 { BT_WIM((bitmap), (bitindex)) &= ~BT_BIW(bitindex); }
114 114
115 115 #ifdef _LP64
116 116 #define BT_BITOUL32(nbits) \
117 117 (((nbits) + BT_NBIPUL32 - 1l) / BT_NBIPUL32)
118 118 #define BT_SIZEOFMAP32(nbits) \
119 119 (BT_BITOUL32(nbits) * sizeof (uint_t))
120 120 #define BT_TEST32(bitmap, bitindex) \
121 121 ((BT_WIM32((bitmap), (bitindex)) & BT_BIW32(bitindex)) ? 1 : 0)
122 122 #define BT_SET32(bitmap, bitindex) \
123 123 { BT_WIM32((bitmap), (bitindex)) |= BT_BIW32(bitindex); }
124 124 #define BT_CLEAR32(bitmap, bitindex) \
125 125 { BT_WIM32((bitmap), (bitindex)) &= ~BT_BIW32(bitindex); }
126 126 #endif /* _LP64 */
127 127
128 128
129 129 /*
130 130 * BIT_ONLYONESET is a private macro not designed for bitmaps of
131 131 * arbitrary size. u must be an unsigned integer/long. It returns
132 132 * true if one and only one bit is set in u.
133 133 */
134 134 #define BIT_ONLYONESET(u) \
135 135 ((((u) == 0) ? 0 : ((u) & ((u) - 1)) == 0))
136 136
137 137 #if defined(_KERNEL) && !defined(_ASM)
138 138 #include <sys/atomic.h>
139 139
140 140 /*
141 141 * return next available bit index from map with specified number of bits
142 142 */
143 143 extern index_t bt_availbit(ulong_t *bitmap, size_t nbits);
144 144 /*
145 145 * find the highest order bit that is on, and is within or below
146 146 * the word specified by wx
147 147 */
148 148 extern int bt_gethighbit(ulong_t *mapp, int wx);
149 149 extern int bt_range(ulong_t *bitmap, size_t *pos1, size_t *pos2,
150 150 size_t end_pos);
151 151 /*
152 152 * Find highest and lowest one bit set.
153 153 * Returns bit number + 1 of bit that is set, otherwise returns 0.
154 154 * Low order bit is 0, high order bit is 31.
155 155 */
156 156 extern int highbit(ulong_t);
157 157 extern int highbit64(uint64_t);
158 158 extern int lowbit(ulong_t);
159 159 extern int bt_getlowbit(ulong_t *bitmap, size_t start, size_t stop);
160 160 extern void bt_copy(ulong_t *, ulong_t *, ulong_t);
161 161
162 162 /*
163 163 * find the parity
↓ open down ↓ |
163 lines elided |
↑ open up ↑ |
164 164 */
165 165 extern int odd_parity(ulong_t);
166 166
167 167 /*
168 168 * Atomically set/clear bits
169 169 * Atomic exclusive operations will set "result" to "-1"
170 170 * if the bit is already set/cleared. "result" will be set
171 171 * to 0 otherwise.
172 172 */
173 173 #define BT_ATOMIC_SET(bitmap, bitindex) \
174 - { atomic_or_long(&(BT_WIM(bitmap, bitindex)), BT_BIW(bitindex)); }
174 + { atomic_or_ulong(&(BT_WIM(bitmap, bitindex)), BT_BIW(bitindex)); }
175 175 #define BT_ATOMIC_CLEAR(bitmap, bitindex) \
176 - { atomic_and_long(&(BT_WIM(bitmap, bitindex)), ~BT_BIW(bitindex)); }
176 + { atomic_and_ulong(&(BT_WIM(bitmap, bitindex)), ~BT_BIW(bitindex)); }
177 177
178 178 #define BT_ATOMIC_SET_EXCL(bitmap, bitindex, result) \
179 179 { result = atomic_set_long_excl(&(BT_WIM(bitmap, bitindex)), \
180 180 (bitindex) % BT_NBIPUL); }
181 181 #define BT_ATOMIC_CLEAR_EXCL(bitmap, bitindex, result) \
182 182 { result = atomic_clear_long_excl(&(BT_WIM(bitmap, bitindex)), \
183 183 (bitindex) % BT_NBIPUL); }
184 184
185 185 /*
186 186 * Extracts bits between index h (high, inclusive) and l (low, exclusive) from
187 187 * u, which must be an unsigned integer.
188 188 */
189 189 #define BITX(u, h, l) (((u) >> (l)) & ((1LU << ((h) - (l) + 1LU)) - 1LU))
190 190
191 191 #endif /* _KERNEL && !_ASM */
192 192
193 193 #ifdef __cplusplus
194 194 }
195 195 #endif
196 196
197 197 #endif /* _SYS_BITMAP_H */
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX