Rev 4065 | Rev 5270 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4065 | Rev 5056 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | #define IDR_SIZE (1 << IDR_BITS) |
33 | #define IDR_SIZE (1 << IDR_BITS) |
34 | #define IDR_MASK ((1 << IDR_BITS)-1) |
34 | #define IDR_MASK ((1 << IDR_BITS)-1) |
Line 35... | Line 35... | ||
35 | 35 | ||
36 | struct idr_layer { |
36 | struct idr_layer { |
37 | int prefix; /* the ID prefix of this idr_layer */ |
37 | int prefix; /* the ID prefix of this idr_layer */ |
38 | DECLARE_BITMAP(bitmap, IDR_SIZE); /* A zero bit means "space here" */ |
38 | int layer; /* distance from leaf */ |
39 | struct idr_layer __rcu *ary[1< |
39 | struct idr_layer __rcu *ary[1< |
- | 40 | int count; /* When zero, we can release it */ |
|
40 | int count; /* When zero, we can release it */ |
41 | union { |
- | 42 | /* A zero bit means "space here" */ |
|
41 | int layer; /* distance from leaf */ |
43 | DECLARE_BITMAP(bitmap, IDR_SIZE); |
42 | struct rcu_head rcu_head; |
44 | struct rcu_head rcu_head; |
- | 45 | }; |
|
Line 43... | Line 46... | ||
43 | }; |
46 | }; |
44 | 47 | ||
45 | struct idr { |
48 | struct idr { |
46 | struct idr_layer __rcu *hint; /* the last layer allocated from */ |
- | |
47 | struct idr_layer __rcu *top; |
49 | struct idr_layer __rcu *hint; /* the last layer allocated from */ |
48 | struct idr_layer *id_free; |
- | |
49 | int layers; /* only valid w/o concurrent changes */ |
50 | struct idr_layer __rcu *top; |
50 | int id_free_cnt; |
51 | int layers; /* only valid w/o concurrent changes */ |
- | 52 | int cur; /* current pos for cyclic allocation */ |
|
- | 53 | spinlock_t lock; |
|
51 | int cur; /* current pos for cyclic allocation */ |
54 | int id_free_cnt; |
Line 52... | Line 55... | ||
52 | spinlock_t lock; |
55 | struct idr_layer *id_free; |
53 | }; |
56 | }; |
54 | 57 | ||
Line 86... | Line 89... | ||
86 | int idr_for_each(struct idr *idp, |
89 | int idr_for_each(struct idr *idp, |
87 | int (*fn)(int id, void *p, void *data), void *data); |
90 | int (*fn)(int id, void *p, void *data), void *data); |
88 | void *idr_get_next(struct idr *idp, int *nextid); |
91 | void *idr_get_next(struct idr *idp, int *nextid); |
89 | void *idr_replace(struct idr *idp, void *ptr, int id); |
92 | void *idr_replace(struct idr *idp, void *ptr, int id); |
90 | void idr_remove(struct idr *idp, int id); |
93 | void idr_remove(struct idr *idp, int id); |
91 | void idr_free(struct idr *idp, int id); |
- | |
92 | void idr_destroy(struct idr *idp); |
94 | void idr_destroy(struct idr *idp); |
93 | void idr_init(struct idr *idp); |
95 | void idr_init(struct idr *idp); |
- | 96 | bool idr_is_empty(struct idr *idp); |
|
Line 94... | Line 97... | ||
94 | 97 | ||
95 | /** |
98 | /** |
96 | * idr_preload_end - end preload section started with idr_preload() |
99 | * idr_preload_end - end preload section started with idr_preload() |
97 | * |
100 | * |
Line 137... | Line 140... | ||
137 | */ |
140 | */ |
138 | #define idr_for_each_entry(idp, entry, id) \ |
141 | #define idr_for_each_entry(idp, entry, id) \ |
139 | for (id = 0; ((entry) = idr_get_next(idp, &(id))) != NULL; ++id) |
142 | for (id = 0; ((entry) = idr_get_next(idp, &(id))) != NULL; ++id) |
Line 140... | Line 143... | ||
140 | 143 | ||
141 | /* |
- | |
142 | * Don't use the following functions. These exist only to suppress |
- | |
143 | * deprecated warnings on EXPORT_SYMBOL()s. |
- | |
144 | */ |
- | |
145 | int __idr_pre_get(struct idr *idp, gfp_t gfp_mask); |
- | |
146 | int __idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id); |
- | |
147 | void __idr_remove_all(struct idr *idp); |
- | |
148 | - | ||
149 | /** |
- | |
150 | * idr_pre_get - reserve resources for idr allocation |
- | |
151 | * @idp: idr handle |
- | |
152 | * @gfp_mask: memory allocation flags |
- | |
153 | * |
- | |
154 | * Part of old alloc interface. This is going away. Use |
- | |
155 | * idr_preload[_end]() and idr_alloc() instead. |
- | |
156 | */ |
- | |
157 | static inline int __deprecated idr_pre_get(struct idr *idp, gfp_t gfp_mask) |
- | |
158 | { |
- | |
159 | return __idr_pre_get(idp, gfp_mask); |
- | |
160 | } |
- | |
161 | - | ||
162 | /** |
- | |
163 | * idr_get_new_above - allocate new idr entry above or equal to a start id |
- | |
164 | * @idp: idr handle |
- | |
165 | * @ptr: pointer you want associated with the id |
- | |
166 | * @starting_id: id to start search at |
- | |
167 | * @id: pointer to the allocated handle |
- | |
168 | * |
- | |
169 | * Part of old alloc interface. This is going away. Use |
- | |
170 | * idr_preload[_end]() and idr_alloc() instead. |
- | |
171 | */ |
- | |
172 | static inline int __deprecated idr_get_new_above(struct idr *idp, void *ptr, |
- | |
173 | int starting_id, int *id) |
- | |
174 | { |
- | |
175 | return __idr_get_new_above(idp, ptr, starting_id, id); |
- | |
176 | } |
- | |
177 | - | ||
178 | /** |
- | |
179 | * idr_get_new - allocate new idr entry |
- | |
180 | * @idp: idr handle |
- | |
181 | * @ptr: pointer you want associated with the id |
- | |
182 | * @id: pointer to the allocated handle |
- | |
183 | * |
- | |
184 | * Part of old alloc interface. This is going away. Use |
- | |
185 | * idr_preload[_end]() and idr_alloc() instead. |
- | |
186 | */ |
- | |
187 | static inline int __deprecated idr_get_new(struct idr *idp, void *ptr, int *id) |
- | |
188 | { |
- | |
189 | return __idr_get_new_above(idp, ptr, 0, id); |
- | |
190 | } |
- | |
191 | - | ||
192 | /** |
- | |
193 | * idr_remove_all - remove all ids from the given idr tree |
- | |
194 | * @idp: idr handle |
- | |
195 | * |
- | |
196 | * If you're trying to destroy @idp, calling idr_destroy() is enough. |
- | |
197 | * This is going away. Don't use. |
- | |
198 | */ |
- | |
199 | static inline void __deprecated idr_remove_all(struct idr *idp) |
- | |
200 | { |
- | |
201 | __idr_remove_all(idp); |
- | |
202 | } |
- | |
203 | - | ||
204 | /* |
144 | /* |
205 | * IDA - IDR based id allocator, use when translation from id to |
145 | * IDA - IDR based id allocator, use when translation from id to |
206 | * pointer isn't necessary. |
146 | * pointer isn't necessary. |
207 | * |
147 | * |
208 | * IDA_BITMAP_LONGS is calculated to be one less to accommodate |
148 | * IDA_BITMAP_LONGS is calculated to be one less to accommodate |