Statistics
| Branch: | Revision:

iof-bird-daemon / lib / resource.h @ 18c8241a

History | View | Annotate | Download (1.57 KB)

1 58ef912c Martin Mares
/*
2
 *        BIRD Resource Manager
3
 *
4
 *        (c) 1998 Martin Mares <mj@ucw.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8
9
#ifndef _BIRD_RESOURCE_H_
10
#define _BIRD_RESOURCE_H_
11
12 1feea03e Martin Mares
#include "lib/lists.h"
13 58ef912c Martin Mares
14
/* Resource */
15
16
typedef struct resource {
17 18c8241a Martin Mares
  node n;                                /* Inside resource pool */
18
  struct resclass *class;                /* Resource class */
19 58ef912c Martin Mares
} resource;
20
21
/* Resource class */
22
23
struct resclass {
24 18c8241a Martin Mares
  char *name;                                /* Resource class name */
25
  unsigned size;                        /* Standard size of single resource */
26
  void (*free)(resource *);                /* Freeing function */
27
  void (*dump)(resource *);                /* Dump to debug output */
28 58ef912c Martin Mares
};
29
30
/* Generic resource manipulation */
31
32
typedef struct pool pool;
33
34 18c8241a Martin Mares
void resource_init(void);
35 58ef912c Martin Mares
pool *rp_new(pool *);                        /* Create new pool */
36 18c8241a Martin Mares
void rp_free(pool *);                        /* Free everything in the pool */
37 58ef912c Martin Mares
void rfree(void *);                        /* Free single resource */
38
void rdump(void *);                        /* Dump to debug output */
39
40 18c8241a Martin Mares
void *ralloc(pool *, struct resclass *);
41
42
extern pool root_pool;
43 58ef912c Martin Mares
44
/* Normal memory blocks */
45
46
void *mb_alloc(pool *, unsigned size);
47 18c8241a Martin Mares
void mb_free(void *);
48 58ef912c Martin Mares
49
/* Memory pools with linear allocation */
50
51
typedef struct mempool mempool;
52
53
mempool *mp_new(pool *, unsigned blk);
54
void *mp_alloc(mempool *, unsigned size);        /* Aligned */
55
void *mp_allocu(mempool *, unsigned size);        /* Unaligned */
56
void *mp_allocz(mempool *, unsigned size);        /* With clear */
57
58
/* Slabs */
59
60
typedef struct slab slab;
61
62
slab *sl_new(pool *, unsigned size);
63
void *sl_alloc(slab *);
64
void sl_free(slab *, void *);
65
66
/* Low-level memory allocation functions, please don't use */
67
68
void *xmalloc(unsigned);
69
#define xfree(x) free(x)
70
71
#endif