| 1 | #pragma once
|
|---|
| 2 |
|
|---|
| 3 | extern "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 |
|
|---|
| 15 | struct 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 |
|
|---|
| 29 | void ?{}( gc_memory_pool* this,
|
|---|
| 30 | size_t size,
|
|---|
| 31 | gc_memory_pool* next,
|
|---|
| 32 | gc_memory_pool* mirror,
|
|---|
| 33 | uint8_t type
|
|---|
| 34 | );
|
|---|
| 35 |
|
|---|
| 36 | void ^?{}(gc_memory_pool* this);
|
|---|
| 37 |
|
|---|
| 38 | struct 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 |
|
|---|
| 48 | void ?{}( 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 |
|
|---|
| 56 | void ^?{}( gc_pool_object_iterator* this );
|
|---|
| 57 |
|
|---|
| 58 | bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs);
|
|---|
| 59 |
|
|---|
| 60 | gc_pool_object_iterator begin(gc_memory_pool* const this);
|
|---|
| 61 | gc_pool_object_iterator end(gc_memory_pool* const);
|
|---|
| 62 |
|
|---|
| 63 | gc_pool_object_iterator* ++?(gc_pool_object_iterator* it);
|
|---|
| 64 |
|
|---|
| 65 | const struct gc_object_header* *?(const gc_pool_object_iterator it);
|
|---|
| 66 | struct gc_object_header* *?(gc_pool_object_iterator it);
|
|---|
| 67 |
|
|---|
| 68 | static 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 |
|
|---|
| 73 | void gc_reset_pool(gc_memory_pool* const pool);
|
|---|
| 74 |
|
|---|
| 75 | static inline size_t gc_pool_size_used(const gc_memory_pool* pool)
|
|---|
| 76 | {
|
|---|
| 77 | return pool->free_p - pool->start_p;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | static inline size_t gc_pool_size_total(const gc_memory_pool* pool)
|
|---|
| 81 | {
|
|---|
| 82 | return pool->end_p - pool->start_p;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | static inline size_t gc_pool_size_left(const gc_memory_pool* pool)
|
|---|
| 86 | {
|
|---|
| 87 | return pool->end_p - pool->free_p;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | void* gc_pool_allocate(gc_memory_pool* const pool, size_t size, bool zero);
|
|---|
| 91 |
|
|---|
| 92 | gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const pool, void* member);
|
|---|