ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
ctor
deferred_resn
demangler
enum
forall-pointer-decay
gc_noraii
jacob/cs343-translation
jenkins-sandbox
memory
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
resolv-new
with_gc
|
Last change
on this file since df4aea7 was df4aea7, checked in by Thierry Delisle <tdelisle@…>, 10 years ago |
|
all implemented files compile
|
-
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 | #include "vector.h"
|
|---|
| 8 |
|
|---|
| 9 | typedef vector(struct gc_memory_pool*, heap_allocator(struct gc_memory_pool*)) pools_table_t;
|
|---|
| 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 |
|
|---|
| 21 | pools_table_t pools_table;
|
|---|
| 22 | size_t pools_table_count;
|
|---|
| 23 | };
|
|---|
| 24 |
|
|---|
| 25 | void ctor(struct gc_state* state);
|
|---|
| 26 |
|
|---|
| 27 | gc_state* gc_get_state();
|
|---|
| 28 |
|
|---|
| 29 | inline bool gc_needs_collect(gc_state* state)
|
|---|
| 30 | {
|
|---|
| 31 | return state->used_space * 2 > state->total_space;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | void gc_collect(gc_state* state);
|
|---|
| 35 |
|
|---|
| 36 | void* gc_try_allocate(gc_state* state, size_t size);
|
|---|
| 37 |
|
|---|
| 38 | void gc_allocate_pool(gc_state* state);
|
|---|
| 39 |
|
|---|
| 40 | bool gc_is_in_heap(const gc_state* state, void* address);
|
|---|
| 41 |
|
|---|
| 42 | bool gc_is_in_to_space(const gc_state* state, void* address);
|
|---|
| 43 |
|
|---|
| 44 | inline uint8_t gc_from_space_code(const gc_state *const this)
|
|---|
| 45 | {
|
|---|
| 46 | return this->from_code;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | struct gc_object_header* gc_get_object_for_ref(gc_state* state, void*);
|
|---|
| 50 |
|
|---|
| 51 | inline void gc_register_allocation(gc_state* state, size_t size)
|
|---|
| 52 | {
|
|---|
| 53 | state->used_space += size;
|
|---|
| 54 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.