source:
src/examples/gc_no_raii/src/internal/state.h
@
4ef8fb3
Last change on this file since 4ef8fb3 was 4ef8fb3, checked in by , 8 years ago | |
---|---|
|
|
File size: 1.2 KB |
Rev | Line | |
---|---|---|
[e47f529] | 1 | #pragma once |
2 | ||
3 | #include <stddef.h> | |
4 | #include <stdint.h> | |
5 | ||
6 | #include "tools.h" | |
[df4aea7] | 7 | #include "vector.h" |
8 | ||
[4ef8fb3] | 9 | typedef vector(struct gc_memory_pool*, heap_allocator(struct gc_memory_pool*)) pools_table_t; |
[e47f529] | 10 | |
11 | struct gc_state | |
12 | { | |
13 | bool is_initialized; | |
14 | uint8_t from_code; | |
15 | struct gc_memory_pool* to_space; | |
16 | struct gc_memory_pool* from_space; | |
17 | ||
18 | size_t total_space; | |
19 | size_t used_space; | |
20 | ||
[4ef8fb3] | 21 | pools_table_t pools_table; |
[df4aea7] | 22 | size_t pools_table_count; |
[e47f529] | 23 | }; |
24 | ||
[16cfd8c] | 25 | void ctor(gc_state* const state); |
26 | ||
27 | void dtor(gc_state* const state); | |
[e47f529] | 28 | |
[385c130] | 29 | gc_state* gc_get_state(); |
[e47f529] | 30 | |
[16cfd8c] | 31 | static inline bool gc_needs_collect(gc_state* state) |
[e47f529] | 32 | { |
33 | return state->used_space * 2 > state->total_space; | |
34 | } | |
35 | ||
[16cfd8c] | 36 | void gc_collect(gc_state* const this); |
[e47f529] | 37 | |
[16cfd8c] | 38 | void* gc_try_allocate(gc_state* const this, size_t size); |
[e47f529] | 39 | |
[16cfd8c] | 40 | void gc_allocate_pool(gc_state* const state); |
[e47f529] | 41 | |
[16cfd8c] | 42 | bool gc_is_in_heap(const gc_state* const state, const void* const address); |
[e47f529] | 43 | |
[16cfd8c] | 44 | bool gc_is_in_to_space(const gc_state* const state, const void* const address); |
[e47f529] | 45 | |
[16cfd8c] | 46 | static inline uint8_t gc_from_space_code(const gc_state *const this) |
[e47f529] | 47 | { |
[df4aea7] | 48 | return this->from_code; |
[e47f529] | 49 | } |
50 | ||
51 | struct gc_object_header* gc_get_object_for_ref(gc_state* state, void*); | |
52 | ||
[16cfd8c] | 53 | static inline void gc_register_allocation(gc_state* state, size_t size) |
[e47f529] | 54 | { |
55 | state->used_space += size; | |
56 | } |
Note: See TracBrowser
for help on using the repository browser.