source: src/examples/gc_no_raii/src/internal/memory_pool.h @ bee4283

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

GC files now compile, still working on a compiling example

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#pragma once
2
3extern "C" {
4#include <stdbool.h>
5#include <stddef.h>
6#include <stdint.h>
7}
8
9#include "tools.h"
10
11#include "card_table.h"
12#include "globals.h"
13#include "state.h"
14
15struct gc_memory_pool
16{
17        struct memory_pool* mirror;
18        struct memory_pool* next;
19
20        uint8_t type_code;
21
22        card_table_t* cards;
23
24        uint8_t* end_p;
25        uint8_t* free_p;
26        uint8_t start_p[1];
27};
28
29void ctor(      gc_memory_pool *const this,
30                size_t size,
31                gc_memory_pool* next,
32                gc_memory_pool* mirror,
33                uint8_t type
34        );
35
36void dtor(gc_memory_pool *const this);
37
38struct gc_pool_object_iterator
39{
40        struct gc_object_header* object;
41        #if _DEBUG
42                intptr_t lower_limit;
43                intptr_t upper_limit;
44        #endif
45};
46
47
48void ctor(
49                gc_pool_object_iterator* const this,
50                struct gc_object_header* start_object
51                #if _DEBUG
52                        , intptr_t pool_start
53                        , intptr_t pool_end
54                #endif
55        );
56
57bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs);
58
59gc_pool_object_iterator begin(gc_memory_pool* const this);
60gc_pool_object_iterator end(gc_memory_pool* const);
61
62gc_pool_object_iterator* ++?(gc_pool_object_iterator* it);
63
64const struct gc_object_header* *?(const gc_pool_object_iterator it);
65struct gc_object_header* *?(gc_pool_object_iterator it);
66
67static inline bool gc_pool_is_from_space(const gc_memory_pool* pool)
68{
69        return gc_from_space_code(gc_get_state()) == pool->type_code;
70}
71
72void gc_reset_pool(gc_memory_pool* const pool);
73
74static inline size_t gc_pool_size_used(const gc_memory_pool* pool)
75{
76        return pool->free_p - pool->start_p;
77}
78
79static inline size_t gc_pool_size_total(const gc_memory_pool* pool)
80{
81        return pool->end_p - pool->start_p;
82}
83
84static inline size_t gc_pool_size_left(const gc_memory_pool* pool)
85{
86        return pool->end_p - pool->free_p;
87}
88
89void* gc_pool_allocate(gc_memory_pool* const pool, size_t size, bool zero);
90
91gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const pool, void* member);
Note: See TracBrowser for help on using the repository browser.