source:
tests/zombies/gc_no_raii/src/internal/card_table.h
@
b2fc7ad9
Last change on this file since b2fc7ad9 was 87b9332, checked in by , 4 years ago | |
---|---|
|
|
File size: 1.3 KB |
Line | |
---|---|
1 | #pragma once |
2 | |
3 | #include "globals.h" |
4 | #include "tools.h" |
5 | |
6 | static inline size_t card_of(void* address) |
7 | { |
8 | size_t card = ( ((intptr_t)address) & CARDS_OFFSET_MASK ) >> CARDS_SIZE_EXP; |
9 | checkf(card < CARDS_COUNT, (const char*)"%lu %lu = (%lx & %lx) >> %lu\n", (size_t)CARDS_COUNT, (size_t)card, (size_t)address, (size_t)CARDS_OFFSET_MASK, (size_t)CARDS_SIZE_EXP); |
10 | check(card < CARDS_COUNT); |
11 | return card; |
12 | } |
13 | |
14 | struct card_table_t |
15 | { |
16 | size_t count; |
17 | void* cards_start[CARDS_COUNT]; |
18 | }; |
19 | |
20 | static inline void ?{}(card_table_t* this) |
21 | { |
22 | this->count = 0; |
23 | } |
24 | |
25 | static inline void ^?{}(card_table_t* this) |
26 | { |
27 | |
28 | } |
29 | |
30 | static inline void* object_at(card_table_t* const this, size_t card_number) |
31 | { |
32 | return card_number < this->count ? this->cards_start[card_number] : NULL; |
33 | } |
34 | |
35 | static inline void register_object(card_table_t* const this, void* object) |
36 | { |
37 | size_t card = card_of(object); |
38 | if(card < this->count) |
39 | { |
40 | intptr_t card_obj_add = (intptr_t)object_at(this, card); |
41 | intptr_t obj_add = (intptr_t)object; |
42 | if(card_obj_add > obj_add) |
43 | { |
44 | this->cards_start[card] = object; |
45 | } |
46 | } |
47 | else |
48 | { |
49 | check(card == this->count); |
50 | this->count++; |
51 | this->cards_start[card] = object; |
52 | } |
53 | } |
54 | |
55 | static inline void reset(card_table_t* const this) |
56 | { |
57 | for(size_t i = 0; i < this->count; i++) |
58 | { |
59 | this->cards_start[i] = NULL; |
60 | } |
61 | this->count = 0; |
62 | } |
Note: See TracBrowser
for help on using the repository browser.