source: src/examples/gc_no_raii/src/internal/memory_pool.h @ 16cfd8c

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

1 error left

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