-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEpoche.h
116 lines (79 loc) · 2.55 KB
/
Epoche.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef ART_EPOCHE_H
#define ART_EPOCHE_H
#include <atomic>
#include <array>
#include "tbb/enumerable_thread_specific.h"
#include "tbb/combinable.h"
namespace ART {
struct LabelDelete {
std::array<void*, 32> nodes;
uint64_t epoche;
std::size_t nodesCount;
LabelDelete *next;
};
class DeletionList {
LabelDelete *headDeletionList = nullptr;
LabelDelete *freeLabelDeletes = nullptr;
std::size_t deletitionListCount = 0;
public:
std::atomic<uint64_t> localEpoche;
size_t thresholdCounter{0};
~DeletionList();
LabelDelete *head();
void add(void *n, uint64_t globalEpoch);
void remove(LabelDelete *label, LabelDelete *prev);
std::size_t size();
std::uint64_t deleted = 0;
std::uint64_t added = 0;
};
class Epoche;
class EpocheGuard;
class ThreadInfo {
friend class Epoche;
friend class EpocheGuard;
Epoche &epoche;
DeletionList &deletionList;
DeletionList & getDeletionList() const;
public:
ThreadInfo(Epoche &epoche);
ThreadInfo(const ThreadInfo &ti) : epoche(ti.epoche), deletionList(ti.deletionList) {
}
~ThreadInfo();
Epoche & getEpoche() const;
};
class Epoche {
friend class ThreadInfo;
std::atomic<uint64_t> currentEpoche{0};
tbb::enumerable_thread_specific<DeletionList> deletionLists;
size_t startGCThreshhold;
public:
Epoche(size_t startGCThreshhold) : startGCThreshhold(startGCThreshhold) { }
~Epoche();
void enterEpoche(ThreadInfo &epocheInfo);
void markNodeForDeletion(void *n, ThreadInfo &epocheInfo);
void exitEpocheAndCleanup(ThreadInfo &info);
void showDeleteRatio();
};
class EpocheGuard {
ThreadInfo &threadEpocheInfo;
public:
EpocheGuard(ThreadInfo &threadEpocheInfo) : threadEpocheInfo(threadEpocheInfo) {
threadEpocheInfo.getEpoche().enterEpoche(threadEpocheInfo);
}
~EpocheGuard() {
threadEpocheInfo.getEpoche().exitEpocheAndCleanup(threadEpocheInfo);
}
};
class EpocheGuardReadonly {
public:
EpocheGuardReadonly(ThreadInfo &threadEpocheInfo) {
threadEpocheInfo.getEpoche().enterEpoche(threadEpocheInfo);
}
~EpocheGuardReadonly() {
}
};
inline ThreadInfo::~ThreadInfo() {
deletionList.localEpoche.store(std::numeric_limits<uint64_t>::max());
}
}
#endif //ART_EPOCHE_H