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 0b0001
10 #define PILE_FL_EXTERN 0b0010
14 typedef void (*pile_cb)(struct cake_pile*, void*);
18 struct llist_header piles;
19 struct llist_header full;
20 struct llist_header partial;
21 struct llist_header free;
26 u32_t pieces_per_cake;
29 char pile_name[PILE_NAME_MAXLEN+1];
34 typedef unsigned short piece_t;
36 #define EO_FREE_PIECE ((piece_t)-1)
38 #define CAKE_FL_SIZE 128
39 #define CAKE_FL_MAXLEN \
40 ((unsigned int)((CAKE_FL_SIZE - sizeof(ptr_t)) / sizeof(piece_t)))
43 piece_t indices[CAKE_FL_MAXLEN];
45 } align(CAKE_FL_SIZE);
49 struct llist_header cakes;
50 struct cake_pile* owner;
52 unsigned int used_pieces;
53 unsigned int next_free;
67 * @param piece_size 每个蛋糕切块儿的大小
68 * @param pg_per_cake 每个蛋糕所占据的页数
69 * @return struct cake_pile*
72 cake_new_pile(char* name,
73 unsigned int piece_size,
74 unsigned int pg_per_cake,
78 cake_set_constructor(struct cake_pile* pile, pile_cb ctor);
87 cake_grab(struct cake_pile* pile);
96 cake_release(struct cake_pile* pile, void* area);
105 cake_reclaim_freed();
107 /********** some handy constructor ***********/
110 cake_ctor_zeroing(struct cake_pile* pile, void* piece);
112 #define DEADCAKE_MARK 0xdeadcafeUL
115 cake_ensure_valid(void* area) {
116 if (unlikely(*(unsigned int*)area == DEADCAKE_MARK)) {
117 fail("access to freed cake piece");
121 #endif /* __LUNAIX_VALLOC_H */