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

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 d67a9a1 was d67a9a1, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

pool alloc functional

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[e47f529]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
[d67a9a1]18        // const struct memory_pool*    pools_table;
19        // size_t                               pools_table_count;
[e47f529]20};
21
[6be0cf9]22void gc_state_ctor(struct gc_state* state);
[e47f529]23
[6be0cf9]24static inline gc_state* gc_get_state()
[e47f529]25{
26        static gc_state s;
[6be0cf9]27        if(!s.is_initialized) gc_state_ctor(&s);
[e47f529]28        return &s;
29}
30
[6be0cf9]31inline bool gc_needs_collect(gc_state* state)
[e47f529]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.