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

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 16cfd8c was 16cfd8c, checked in by Thierry Delisle <tdelisle@…>, 10 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.