chore: fix almost *ALL* warnings.
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / cake.h
1 #ifndef __LUNAIX_CAKE_H
2 #define __LUNAIX_CAKE_H
3
4 #include <lunaix/ds/llist.h>
5
6 #define PILE_NAME_MAXLEN 20
7
8 #define PILE_CACHELINE 1
9
10 struct cake_pile;
11
12 typedef void (*pile_cb)(struct cake_pile*, void*);
13
14 struct cake_pile
15 {
16     struct llist_header piles;
17     struct llist_header full;
18     struct llist_header partial;
19     struct llist_header free;
20     u32_t offset;
21     u32_t piece_size;
22     u32_t cakes_count;
23     u32_t alloced_pieces;
24     u32_t pieces_per_cake;
25     u32_t pg_per_cake;
26     char pile_name[PILE_NAME_MAXLEN];
27
28     pile_cb ctor;
29 };
30
31 typedef unsigned int piece_index_t;
32
33 #define EO_FREE_PIECE ((u32_t)-1)
34
35 struct cake_s
36 {
37     struct llist_header cakes;
38     void* first_piece;
39     unsigned int used_pieces;
40     unsigned int next_free;
41     piece_index_t free_list[0];
42 };
43
44 /**
45  * @brief 创建一个蛋糕堆
46  *
47  * @param name 堆名称
48  * @param piece_size 每个蛋糕切块儿的大小
49  * @param pg_per_cake 每个蛋糕所占据的页数
50  * @return struct cake_pile*
51  */
52 struct cake_pile*
53 cake_new_pile(char* name,
54               unsigned int piece_size,
55               unsigned int pg_per_cake,
56               int options);
57
58 void
59 cake_set_constructor(struct cake_pile* pile, pile_cb ctor);
60
61 /**
62  * @brief 拿一块儿蛋糕
63  *
64  * @param pile
65  * @return void*
66  */
67 void*
68 cake_grab(struct cake_pile* pile);
69
70 /**
71  * @brief 归还一块儿蛋糕
72  *
73  * @param pile
74  * @param area
75  */
76 int
77 cake_release(struct cake_pile* pile, void* area);
78
79 void
80 cake_init();
81
82 void
83 cake_export();
84
85 /********** some handy constructor ***********/
86
87 void
88 cake_ctor_zeroing(struct cake_pile* pile, void* piece);
89
90 #endif /* __LUNAIX_VALLOC_H */