-
Notifications
You must be signed in to change notification settings - Fork 0
/
holder_test.cpp
54 lines (43 loc) · 869 Bytes
/
holder_test.cpp
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
#include "holder.hpp"
//const int thread_count = 3;
struct holder_test {
struct element {
intptr_t ver1;
intptr_t ver2;
element(intptr_t v) : ver1(v), ver2(v) {}
element() = default;
bool ok() {
return ver1 == ver2;
}
};
holder<element> hold;
void before() {
}
void thread(int thread_idx) {
intptr_t prev_ver = 0;
while(prev_ver < 10) {
element value;
intptr_t ver = hold.get(&value);
if (ver == holder<element>::INVALID_VERSION)
continue;
assert(ver >= prev_ver);
assert(value.ok());
assert(value.ver1 == ver);
value = element(ver + 1);
hold.update(ver + 1, &value);
prev_ver = ver + 1;
}
}
void after() {
}
holder_test(int thread_count) {}
};
RELACY_FIXTURE(holder_fixture, holder_test, 3);
int main()
{
#ifdef RELACY
rl::simulate<holder_fixture>();
#else
run_test<holder_test>(3);
#endif
}