Refactor fellow_busy_region_free()

As the fdr argument is from fbo->region, we should DTRT for this
situation and not bloat the code with a loop and stuff...

Motivated by #39
parent b529b5e4
......@@ -2183,28 +2183,26 @@ static void
fellow_busy_region_free(struct fellow_busy *fbo, struct buddy_off_extent *fdr)
{
struct fellow_cache *fc;
unsigned u;
ssize_t u;
CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC);
fc = fbo->fc;
CHECK_OBJ_NOTNULL(fc, FELLOW_CACHE_MAGIC);
AN(fbo->nregion);
u = fbo->nregion;
while (u--) {
if (fdr != &fbo->region[u])
continue;
fellow_region_free(fc->ffd, fdr);
fbo->nregion--;
assert(u <= fbo->nregion);
if (u < fbo->nregion) {
memmove(&fbo->region[u], &fbo->region[u] + 1,
(fbo->nregion - u) * sizeof *fdr);
}
u = fdr - &fbo->region[0];
assert(u >= 0);
assert(u < fbo->nregion);
// obviously: assert(&fbo->region[u] == fdr);
fellow_region_free(fc->ffd, fdr);
if (u == --fbo->nregion)
return;
}
WRONG("region to free not found");
memmove(&fbo->region[u], &fbo->region[u + 1],
(fbo->nregion - (size_t)u) * sizeof *fdr);
}
#ifdef TEST_DRIVER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment