source: tests/zombies/gc_no_raii/src/internal/memory_pool.h @ ba068c0

Last change on this file since ba068c0 was 87b9332, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Moved 'examples/' to 'tests/zombies/'.

  • Property mode set to 100644
File size: 1.9 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 ?{}(       gc_memory_pool* this,
30                size_t size,
31                gc_memory_pool* next,
32                gc_memory_pool* mirror,
33                uint8_t type
34        );
35
36void ^?{}(gc_memory_pool* this);
37
38struct gc_pool_object_iterator
39{
40        struct gc_object_header* object;
41        #ifndef NDEBUG
42                intptr_t lower_limit;
43                intptr_t upper_limit;
44        #endif
45};
46
47
48void ?{}(       gc_pool_object_iterator* this,
49                struct gc_object_header* start_object
50                #ifndef NDEBUG
51                        , intptr_t pool_start
52                        , intptr_t pool_end
53                #endif
54        );
55
56void ^?{}( gc_pool_object_iterator* this );
57
58bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs);
59
60gc_pool_object_iterator begin(gc_memory_pool* const this);
61gc_pool_object_iterator end(gc_memory_pool* const);
62
63gc_pool_object_iterator* ++?(gc_pool_object_iterator* it);
64
65const struct gc_object_header* *?(const gc_pool_object_iterator it);
66struct gc_object_header* *?(gc_pool_object_iterator it);
67
68static inline bool gc_pool_is_from_space(const gc_memory_pool* pool)
69{
70        return gc_from_space_code(gc_get_state()) == pool->type_code;
71}
72
73void gc_reset_pool(gc_memory_pool* const pool);
74
75static inline size_t gc_pool_size_used(const gc_memory_pool* pool)
76{
77        return pool->free_p - pool->start_p;
78}
79
80static inline size_t gc_pool_size_total(const gc_memory_pool* pool)
81{
82        return pool->end_p - pool->start_p;
83}
84
85static inline size_t gc_pool_size_left(const gc_memory_pool* pool)
86{
87        return pool->end_p - pool->free_p;
88}
89
90void* gc_pool_allocate(gc_memory_pool* const pool, size_t size, bool zero);
91
92gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const pool, void* member);
Note: See TracBrowser for help on using the repository browser.