source: src/examples/gc_no_raii/src/internal/card_table.h @ e8b15358

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

1 error left

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