source: src/examples/gc_no_raii/src/internal/card_table.h @ 46f1d20

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 46f1d20 was 46f1d20, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

some changes to checks in gc which are very intrusive

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#pragma once
2
3#include "globals.h"
4#include "tools.h"
5
6static inline size_t card_of(void* address)
7{
8        size_t card = ( ((intptr_t)address) & CARDS_OFFSET_MASK ) >> CARDS_SIZE_EXP;
9        check(card < CARDS_COUNT);
10        return card;
11}
12
13struct card_table_t
14{
15        size_t count;
16        void* cards_start[CARDS_COUNT];
17};
18
19static inline void ctor_card(card_table_t* const this)
20{
21        this->count = 0;
22}
23
24static inline void dtor_card(card_table_t* const this)
25{
26
27}
28
29static inline void* object_at(card_table_t* const this, size_t card_number)
30{
31        return card_number < this->count ? this->cards_start[card_number] : NULL;
32}
33
34static inline void register_object(card_table_t* const this, void* object)
35{
36        size_t card = card_of(object);
37        if(card < this->count)
38        {
39                intptr_t card_obj_add = (intptr_t)object_at(this, card);
40                intptr_t obj_add = (intptr_t)object;
41                if(card_obj_add > obj_add)
42                {
43                        this->cards_start[card] = object;
44                }
45        }
46        else
47        {
48                check(card == this->count);
49                this->count++;
50                this->cards_start[card] = object;
51        }
52}
53
54static inline void reset(card_table_t* const this)
55{
56        for(size_t i = 0; i < this->count; i++)
57        {
58                this->cards_start[i] = NULL;
59        }
60        this->count = 0;
61}
Note: See TracBrowser for help on using the repository browser.