-
Notifications
You must be signed in to change notification settings - Fork 0
/
GCPhase.h
82 lines (59 loc) · 1.75 KB
/
GCPhase.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef CPPGCPTR_GCPHASE_H
#define CPPGCPTR_GCPHASE_H
#include <iostream>
#include <string>
#include <atomic>
#include <memory>
#include "PhaseEnum.h"
#include "SpinReadWriteLock.h"
#include "MutexReadWriteLock.h"
#include "WeakSpinReadWriteLock.h"
#include "SpinLock.h"
#define USE_SPINLOCK 0
class GCPhase {
private:
static std::atomic<eGCPhase> gcPhase;
static std::atomic<MarkState> currentMarkState;
static IReadWriteLock* stwLock;
static IReadWriteLock* gcPhaseLock;
public:
static eGCPhase getGCPhase();
static std::string getGCPhaseString();
static MarkState getCurrentMarkState() {
return currentMarkState;
}
static MarkStateBit getCurrentMarkStateBit();
static void SwitchToNextPhase();
static bool needSweep(MarkState markState);
static bool needSweep(MarkStateBit markState);
static bool needSelfHeal(MarkState markState);
static bool isLiveObject(MarkStateBit);
static bool isLiveObject(MarkState);
static bool duringGC() {
return gcPhase != eGCPhase::NONE;
}
static bool duringMarking() {
return gcPhase == eGCPhase::CONCURRENT_MARK || gcPhase == eGCPhase::REMARK;
}
static bool duringMarking(const eGCPhase& gcPhase) {
return gcPhase == eGCPhase::CONCURRENT_MARK || gcPhase == eGCPhase::REMARK;
}
static void EnterCriticalSection() {
stwLock->lockRead();
}
static void LeaveCriticalSection() {
stwLock->unlockRead();
}
static IReadWriteLock* getSTWLock() {
return stwLock;
}
class RAIISTWLock {
private:
bool owns;
public:
RAIISTWLock();
explicit RAIISTWLock(bool doNotLockAtRemarkPhase);
~RAIISTWLock();
};
};
#endif //CPPGCPTR_GCPHASE_H