-
Notifications
You must be signed in to change notification settings - Fork 64
/
tgc.h
51 lines (42 loc) · 1.19 KB
/
tgc.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef TGC_H
#define TGC_H
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <setjmp.h>
enum {
TGC_MARK = 0x01,
TGC_ROOT = 0x02,
TGC_LEAF = 0x04
};
typedef struct {
void *ptr;
int flags;
size_t size, hash;
void (*dtor)(void*);
} tgc_ptr_t;
typedef struct {
void *bottom;
int paused;
uintptr_t minptr, maxptr;
tgc_ptr_t *items, *frees;
double loadfactor, sweepfactor;
size_t nitems, nslots, mitems, nfrees;
} tgc_t;
void tgc_start(tgc_t *gc, void *stk);
void tgc_stop(tgc_t *gc);
void tgc_pause(tgc_t *gc);
void tgc_resume(tgc_t *gc);
void tgc_run(tgc_t *gc);
void *tgc_alloc(tgc_t *gc, size_t size);
void *tgc_calloc(tgc_t *gc, size_t num, size_t size);
void *tgc_realloc(tgc_t *gc, void *ptr, size_t size);
void tgc_free(tgc_t *gc, void *ptr);
void *tgc_alloc_opt(tgc_t *gc, size_t size, int flags, void(*dtor)(void*));
void *tgc_calloc_opt(tgc_t *gc, size_t num, size_t size, int flags, void(*dtor)(void*));
void tgc_set_dtor(tgc_t *gc, void *ptr, void(*dtor)(void*));
void tgc_set_flags(tgc_t *gc, void *ptr, int flags);
int tgc_get_flags(tgc_t *gc, void *ptr);
void(*tgc_get_dtor(tgc_t *gc, void *ptr))(void*);
size_t tgc_get_size(tgc_t *gc, void *ptr);
#endif