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