MCPcopy Create free account
hub / github.com/HelenOS/helenos / bitmap_clear_range

Function bitmap_clear_range

kernel/generic/src/adt/bitmap.c:166–213  ·  view source on GitHub ↗

Clear range of bits. * * @param bitmap Bitmap structure. * @param start Starting bit. * @param count Number of bits to clear. * */

Source from the content-addressed store, hash-verified

164 *
165 */
166void bitmap_clear_range(bitmap_t *bitmap, size_t start, size_t count)
167{
168 assert(start + count <= bitmap->elements);
169
170 if (count == 0)
171 return;
172
173 size_t start_byte = start / BITMAP_ELEMENT;
174 size_t aligned_start = ALIGN_UP(start, BITMAP_ELEMENT);
175
176 /* Leading unaligned bits */
177 size_t lub = min(aligned_start - start, count);
178
179 /* Aligned middle bits */
180 size_t amb = (count > lub) ? (count - lub) : 0;
181
182 /* Trailing aligned bits */
183 size_t tab = amb % BITMAP_ELEMENT;
184
185 if (start + count < aligned_start) {
186 /* Set bits in the middle of byte */
187 bitmap->bits[start_byte] &=
188 ~(((1 << lub) - 1) << (start & BITMAP_REMAINER));
189 return;
190 }
191
192 if (lub) {
193 /* Make sure to clear any leading unaligned bits. */
194 bitmap->bits[start_byte] &=
195 (1 << (BITMAP_ELEMENT - lub)) - 1;
196 }
197
198 size_t i;
199
200 for (i = 0; i < amb / BITMAP_ELEMENT; i++) {
201 /* The middle bits can be cleared byte by byte. */
202 bitmap->bits[aligned_start / BITMAP_ELEMENT + i] =
203 ALL_ZEROES;
204 }
205
206 if (tab) {
207 /* Make sure to clear any trailing aligned bits. */
208 bitmap->bits[aligned_start / BITMAP_ELEMENT + i] &=
209 ~((1 << tab) - 1);
210 }
211
212 bitmap->next_fit = start_byte;
213}
214
215/** Copy portion of one bitmap into another bitmap.
216 *

Callers 6

ddi_iospace_enable_archFunction · 0.85
ddi_iospace_disable_archFunction · 0.85
zone_merge_internalFunction · 0.85
zone_constructFunction · 0.85
bitmap_copyFunction · 0.85
ddi_iospace_enable_archFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected