-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgc.h
46 lines (33 loc) · 870 Bytes
/
gc.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
#pragma once
#include <stdbool.h>
typedef void (*gc_free_t)(void *);
typedef struct gc_ObjNode gc_ObjNode;
typedef struct gc_Children {
struct gc_Children *next;
gc_ObjNode *ch;
} gc_Children;
gc_Children *gc_Children_new(gc_ObjNode *);
// 用**是因为它可能为NULL,下同
void gc_Children_append(gc_Children *, gc_ObjNode *);
void gc_Children_remove(gc_Children *, gc_ObjNode *);
typedef struct gc_Object {
struct gc_Object *next;
void *ptr;
gc_free_t freer;
bool vis;
} gc_Object;
gc_Object *gc_Object_new(void *, gc_free_t);
typedef struct gc_ObjNode {
gc_Children *chs;
gc_Object *obj;
} gc_ObjNode;
gc_ObjNode *gc_ObjNode_new(gc_Object *);
void gc_ObjNode_recursive(gc_ObjNode *);
typedef struct GC {
gc_Object *objs;
gc_ObjNode *gcmap;
} GC;
extern GC gc;
void gc_init();
void gc_add_obj(gc_Object *obj);
void gc_collect();