Unify process_alloc() and process_realloc() with PROCESS_ALLOC_MODE_REALLOC bit
[moveable_pool.git] / pool.h
1 #ifndef _POOL_H
2 #define _POOL_H 1
3
4 #include <stdbool.h>
5
6 struct pool_item {
7   struct pool_item *prev;
8   struct pool_item *next;
9   int base;
10   int limit;
11 };
12
13 struct pool_head {
14   struct pool_item item;
15   int avail;
16   void (*move)(struct pool_item *item, int new_base);
17   void (*move_up)(struct pool_item *item, int new_limit);
18 };
19
20 #define POOL_ALLOC_MODE_REALLOC 1
21 #define POOL_ALLOC_MODE_LAST_FIT 2
22 #define POOL_ALLOC_MODE_MOVEABLE 4
23
24 void pool_init(
25   struct pool_head *head,
26   int base,
27   int limit,
28   void (*move)(struct pool_item *item, int new_base),
29   void (*move_up)(struct pool_item *item, int new_limit)
30 );
31 bool pool_alloc(
32   struct pool_head *head,
33   struct pool_item *item,
34   int size,
35   int mode,
36   ...
37 );
38 void pool_free(struct pool_head *head, struct pool_item *item);
39
40 #endif