-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_finalizer.cc
77 lines (75 loc) · 1.74 KB
/
test_finalizer.cc
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
#include "thread.h"
#include "pair.h"
size_t v_finalized;
t_root<t_slot_of<t_pair>> v_resurrected;
int main(int argc, char* argv[])
{
t_engine<t_type>::t_options options;
if (argc > 1) std::sscanf(argv[1], "%zu", &options.v_collector__threshold);
options.v_verbose = true;
t_engine_with_finalizer engine(options, [](auto RECYCLONE__SPILL a_p)
{
f_epoch_point<t_type>();
if (a_p->f_type() != &t_type_of<t_pair>::v_instance) return;
auto s = f_string(a_p);
f_epoch_region<t_type>([&]
{
std::printf("%s -> ", s.c_str());
});
auto p = static_cast<t_pair*>(a_p);
if (p->v_head && p->v_head->f_type() == &t_type_of<t_symbol>::v_instance && static_cast<t_symbol*>(p->v_head)->v_name == "resurrected"sv) {
++v_finalized;
f_epoch_region<t_type>([]
{
std::printf("finalized\n");
});
} else {
p->v_head = f_new<t_symbol>("resurrected"sv);
v_resurrected = p;
p->f_finalizee__(true);
f_epoch_region<t_type>([]
{
std::printf("resurrected\n");
});
}
});
return [&]() RECYCLONE__NOINLINE
{
f_with_scratch([]
{
f_epoch_point<t_type>();
f_new<t_pair>(f_new<t_symbol>("foo"sv))->f_finalizee__(true);
});
engine.f_collect();
engine.f_finalize();
f_with_scratch([]
{
f_epoch_point<t_type>();
auto s = f_string(v_resurrected);
f_epoch_region<t_type>([&]
{
std::printf("resurrected: %s\n", s.c_str());
});
#ifndef NDEBUG
assert(v_resurrected);
#endif
v_resurrected = nullptr;
});
engine.f_collect();
engine.f_finalize();
f_epoch_region<t_type>([]
{
std::printf("finalized: %zu\n", v_finalized);
});
#ifndef NDEBUG
assert(v_finalized == 1);
#endif
engine.f_join_foregrounds();
#ifdef NDEBUG
std::exit(0);
#else
engine.f_quit_finalizer();
#endif
return 0;
}();
}