source: src/examples/gc_no_raii/internal/state.h @ e47f529

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationresolv-newwith_gc
Last change on this file since e47f529 was e47f529, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

more conversion and compile seems to work well

  • Property mode set to 100644
File size: 1.1 KB
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(gc_state* state);
23
24inline gc_state* get_state()
25{
26        static gc_state s;
27        if(!s.is_initialized) gc_state_ctor(s);
28        return &s;
29}
30
31inline bool needs_collect(gc_state* state)
32{
33        return state->used_space * 2 > state->total_space;
34}
35
36void gc_collect(gc_state* state);
37
38void* gc_try_allocate(gc_state* state, size_t size);
39
40void gc_allocate_pool(gc_state* state);
41
42bool gc_is_in_heap(const gc_state* state, void* address);
43
44bool gc_is_in_to_space(const gc_state* state, void* address);
45
46inline uint8_t gc_from_space_code(const gc_state* state)
47{
48        return state->from_code;
49}
50
51struct gc_object_header* gc_get_object_for_ref(gc_state* state, void*);
52
53inline void gc_register_allocation(gc_state* state, size_t size)
54{
55        state->used_space += size;
56}
Note: See TracBrowser for help on using the repository browser.