#pragma once

/**
 * Simple interface to detect when the GC decided to run finalizers.
 *
 * Useful to be able to wait until the GC has run finalizers, without having to do "too many" calls
 * to collect() just to be safe.
 */

// Helper to clear out data on the stack.
NOINLINE void clearStack(const size_t toClear = 128);

// Create a finalizer canary. The value will be added to the global value 'finalized' once the
// allocation has been finalized.
void canaryCreate(Engine &e, size_t value = 1);

// Get the current value of the finalized canaries.
size_t canaryFinalized();

// Call gc.collect() until at least one canary has been finalized in related to the observed value
// of 'original' from 'canaryFinalized'.
void canaryCollect(Engine &e, size_t original, size_t count = 1);

// Run finalizers. Creates a canary, then calls 'canaryCollect'.
void runFinalizers(Engine &e);
