Skip to content

Commit d234e9e

Browse files
committed
LibGC: Add GC::Heap::the()
There's only ever one GC::Heap per process, so let's have a way to find it even when you have no context.
1 parent 8b1f2e4 commit d234e9e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Libraries/LibGC/Heap.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,18 @@
3030

3131
namespace GC {
3232

33+
static Heap* s_the;
34+
35+
Heap& Heap::the()
36+
{
37+
return *s_the;
38+
}
39+
3340
Heap::Heap(void* private_data, AK::Function<void(HashMap<Cell*, GC::HeapRoot>&)> gather_embedder_roots)
3441
: HeapBase(private_data)
3542
, m_gather_embedder_roots(move(gather_embedder_roots))
3643
{
44+
s_the = this;
3745
static_assert(HeapBlock::min_possible_cell_size <= 32, "Heap Cell tracking uses too much data!");
3846
m_size_based_cell_allocators.append(make<CellAllocator>(64));
3947
m_size_based_cell_allocators.append(make<CellAllocator>(96));

Libraries/LibGC/Heap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class GC_API Heap : public HeapBase {
3838
explicit Heap(void* private_data, AK::Function<void(HashMap<Cell*, GC::HeapRoot>&)> gather_embedder_roots);
3939
~Heap();
4040

41+
static Heap& the();
42+
4143
template<typename T, typename... Args>
4244
Ref<T> allocate(Args&&... args)
4345
{

0 commit comments

Comments
 (0)