-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemory-pool.cc
54 lines (41 loc) · 1.16 KB
/
memory-pool.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
#pragma once
namespace KERF_NAMESPACE {
void MEMORY_POOL::pool_dealloc(SLAB* z)
{
// HACK TODO, technically, this is determined by the layout, "where" the lane value lives (if anywhere! it may be implicit)
char lane = z->m_memory_expansion_size;
#if TEST_TRACK_ALLOCATIONS
if(!test_alloc_tracker.contains(z)) {
die(Test alloc tracker attempted to repool a memory address element we did not have tracked in the set.)
}
critical_section_wrapper([&]{
#endif
#if TEST_TRY_POOL_ZEROES_DEALLOC
bzero(z, POW2(lane));
#endif
#if !TEST_TRY_POOL_NEVER_REUSES_STRUCTS
pool_repool(z, lane);
#endif
#if TEST_TRACK_ALLOCATIONS
test_alloc_tracker.erase(z);
});
#endif
}
MEMORY_POOL::~MEMORY_POOL()
{
#if TEST_TRACK_ALLOCATIONS
if(!test_alloc_tracker.empty())
{
std::cerr << "Error: Pool memory still resident. Active memory structures: " << test_alloc_tracker.size() << "\n";
if(!The_Did_Interrupt_Flag)
{
for(auto v : test_alloc_tracker)
{
SLOP u((SLAB*)v);
std::cerr << "unfreed " << v << " [+" << (I)u.layout()->header_get_slab_reference_count() << "]" << ": " << (u) << "\n";
}
}
}
#endif
}
} // namespace