-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGCObject.h
More file actions
60 lines (48 loc) · 1.24 KB
/
GCObject.h
File metadata and controls
60 lines (48 loc) · 1.24 KB
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
52
53
54
55
56
57
58
59
60
#ifndef GC_OBJECT_H
#define GC_OBJECT_H
struct GCObject {
enum GCObjectType {
GCT_String,
GCT_Array,
GCT_Function,
};
enum GCState {
GCS_Unaccess,
GCS_Unscan,
GCS_Scan,
};
GCObjectType type;
mutable GCState state;
GCObject *next;
GCObject* gcAccess() const {
if (state == GCS_Unaccess) {
state = GCS_Unscan;
return (GCObject*)this;
}
return NULL;
}
protected:
GCObject(GCObjectType _type): type(_type), state(GCS_Unaccess){}
private:
GCObject& operator = (const GCObject &);
GCObject(const GCObject& );
};
class GCObjectManager {
public:
void link(GCObject *obj);
void performFullGC();
int getObjectCount() const { return m_objCount; }
static void createInstance() { s_ins = new GCObjectManager(); }
static void destroyInstance() { delete s_ins; }
static GCObjectManager* instance() { return s_ins; }
private:
GCObject *m_head;
int m_objCount;
private:
GCObjectManager(): m_head(NULL), m_objCount(0) {}
~GCObjectManager();
GCObjectManager(const GCObjectManager&);
GCObjectManager& operator = (const GCObjectManager&);
static GCObjectManager *s_ins;
};
#endif