source: src/examples/gc_no_raii/src/internal/state.h @ 3365b37

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 3365b37 was 385c130, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

pre merge

  • Property mode set to 100644
File size: 1015 bytes
Line 
1#pragma once
2
3#include <stddef.h>
4#include <stdint.h>
5
6#include "tools.h"
7
8struct gc_state
9{
10        bool is_initialized;
11        uint8_t from_code;
12        struct gc_memory_pool* to_space;
13        struct gc_memory_pool* from_space;
14
15        size_t total_space;
16        size_t used_space;
17
18        // const struct memory_pool*    pools_table;
19        // size_t                               pools_table_count;
20};
21
22void gc_state_ctor(struct gc_state* state);
23
24gc_state* gc_get_state();
25
26inline bool gc_needs_collect(gc_state* state)
27{
28        return state->used_space * 2 > state->total_space;
29}
30
31void gc_collect(gc_state* state);
32
33void* gc_try_allocate(gc_state* state, size_t size);
34
35void gc_allocate_pool(gc_state* state);
36
37bool gc_is_in_heap(const gc_state* state, void* address);
38
39bool gc_is_in_to_space(const gc_state* state, void* address);
40
41inline uint8_t gc_from_space_code(const gc_state* state)
42{
43        return state->from_code;
44}
45
46struct gc_object_header* gc_get_object_for_ref(gc_state* state, void*);
47
48inline void gc_register_allocation(gc_state* state, size_t size)
49{
50        state->used_space += size;
51}
Note: See TracBrowser for help on using the repository browser.