summaryrefslogtreecommitdiffstats
path: root/src/memblock.h
blob: 0c215e85bf54a5e946e12583e5c4964d49f4d5c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef foomemblockhfoo
#define foomemblockhfoo

#include <sys/types.h>
#include <inttypes.h>

enum memblock_type { MEMBLOCK_FIXED, MEMBLOCK_APPENDED, MEMBLOCK_DYNAMIC };

struct memblock {
    enum memblock_type type;
    unsigned ref;
    size_t length;
    void *data;
};

struct memchunk {
    struct memblock *memblock;
    size_t index, length;
};

struct memblock *memblock_new(size_t length);
struct memblock *memblock_new_fixed(void *data, size_t length);
struct memblock *memblock_new_dynamic(void *data, size_t length);

void memblock_unref(struct memblock*b);
struct memblock* memblock_ref(struct memblock*b);

void memblock_unref_fixed(struct memblock*b);

#define memblock_assert_exclusive(b) assert((b)->ref == 1)

void memchunk_make_writable(struct memchunk *c);

extern unsigned memblock_count, memblock_total;

#endif