(piece_size + sizeof(piece_index_t)),
.pg_per_cake = pg_per_cake };
- unsigned int overhead_size =
- sizeof(struct cake_s) + pile->pieces_per_cake * sizeof(piece_index_t);
+ unsigned int free_list_size = pile->pieces_per_cake * sizeof(piece_index_t);
- pile->offset = ROUNDUP(overhead_size, offset);
+ pile->offset = ROUNDUP(sizeof(struct cake_s) + free_list_size, offset);
+ pile->pieces_per_cake -= ICEIL((pile->offset - free_list_size), piece_size);
strncpy(&pile->pile_name, name, PILE_NAME_MAXLEN);
pos = list_entry(pile->free.next, typeof(*pos), cakes);
}
-found:
piece_index_t found_index = pos->next_free;
pos->next_free = pos->free_list[found_index];
pos->used_pieces++;
int
cake_release(struct cake_pile* pile, void* area)
{
- piece_index_t area_index;
+ piece_index_t piece_index;
struct cake_s *pos, *n;
struct llist_header* hdrs[2] = { &pile->full, &pile->partial };
if (pos->first_piece > area) {
continue;
}
- area_index =
+ piece_index =
(uintptr_t)(area - pos->first_piece) / pile->piece_size;
- if (area_index < pile->pieces_per_cake) {
+ if (piece_index < pile->pieces_per_cake) {
goto found;
}
}
return 0;
found:
- pos->free_list[area_index] = pos->next_free;
- pos->next_free = area_index;
+ pos->free_list[piece_index] = pos->next_free;
+ pos->next_free = piece_index;
pos->used_pieces--;
pile->alloced_pieces--;