1 #ifndef __LUNAIX_CAKE_H
2 #define __LUNAIX_CAKE_H
4 #include <lunaix/ds/llist.h>
5 #include <lunaix/spike.h>
7 #define PILE_NAME_MAXLEN 20
9 #define PILE_ALIGN_CACHE 1
13 typedef void (*pile_cb)(struct cake_pile*, void*);
17 struct llist_header piles;
18 struct llist_header full;
19 struct llist_header partial;
20 struct llist_header free;
25 u32_t pieces_per_cake;
27 char pile_name[PILE_NAME_MAXLEN+1];
32 typedef unsigned int piece_index_t;
34 #define EO_FREE_PIECE ((u32_t)-1)
38 struct llist_header cakes;
40 unsigned int used_pieces;
41 unsigned int next_free;
42 piece_index_t free_list[0];
49 * @param piece_size 每个蛋糕切块儿的大小
50 * @param pg_per_cake 每个蛋糕所占据的页数
51 * @return struct cake_pile*
54 cake_new_pile(char* name,
55 unsigned int piece_size,
56 unsigned int pg_per_cake,
60 cake_set_constructor(struct cake_pile* pile, pile_cb ctor);
69 cake_grab(struct cake_pile* pile);
78 cake_release(struct cake_pile* pile, void* area);
86 /********** some handy constructor ***********/
89 cake_ctor_zeroing(struct cake_pile* pile, void* piece);
91 #define DEADCAKE_MARK 0xdeadcafeUL
94 cake_ensure_valid(void* area) {
95 if (unlikely(*(unsigned int*)area == DEADCAKE_MARK)) {
96 fail("access to freed cake piece");
100 #endif /* __LUNAIX_VALLOC_H */