X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/a4ec38a4c7ef61b04b92d34637c846a8e2e95f7f..a9cfeffd21239290ab1da46a952fe5789ae3f6de:/lunaix-os/kernel/mm/cake.c diff --git a/lunaix-os/kernel/mm/cake.c b/lunaix-os/kernel/mm/cake.c index 5aa9bef..5e03d34 100644 --- a/lunaix-os/kernel/mm/cake.c +++ b/lunaix-os/kernel/mm/cake.c @@ -120,6 +120,12 @@ cake_new_pile(char* name, return pile; } +void +cake_set_constructor(struct cake_pile* pile, pile_cb ctor) +{ + pile->ctor = ctor; +} + void* cake_grab(struct cake_pile* pile) { @@ -147,8 +153,14 @@ cake_grab(struct cake_pile* pile) llist_append(&pile->partial, &pos->cakes); } - return (void*)((uintptr_t)pos->first_piece + - found_index * pile->piece_size); + void* ptr = + (void*)((uintptr_t)pos->first_piece + found_index * pile->piece_size); + + if (pile->ctor) { + pile->ctor(pile, ptr); + } + + return ptr; } int @@ -188,4 +200,10 @@ found: } return 1; +} + +void +cake_ctor_zeroing(struct cake_pile* pile, void* piece) +{ + memset(piece, 0, pile->piece_size); } \ No newline at end of file