use super::raw_pool::*;
use super::free::*;
pub unsafe fn base_clean(pool: &mut RawPool,
full_fn: &Fn(&mut RawPool, Option<*mut Free>, &mut Full)
-> Option<*mut Free>) {
let poolptr = pool as *mut RawPool;
let mut block_maybe = (*poolptr).first_block();
let mut last_freed: Option<*mut Free> = None;
while let Some(mut block) = block_maybe {
last_freed = match (*block).ty() {
BlockType::Free => {
let free = (*block).as_free_mut();
match last_freed {
Some(ref last) => {
Some((**last).join(pool, free))
}
None => {
Some(free as *mut Free)
}
}
}
BlockType::Full => {
let full = (*block).as_full_mut();
last_freed = full_fn(pool, last_freed, full);
if let Some(ref last) = last_freed {
block = pool.block((**last).block());
}
last_freed
}
};
block_maybe = match (*block).next_mut(pool) {
Some(b) => Some(b as *mut Block),
None => None,
};
}
if let Some(ref last) = last_freed {
assert_eq!((**last).block() + (**last).blocks(), pool.heap_block);
pool.heap_block -= (**last).blocks();
(**last).remove(pool);
}
}