/home/travis/build/MoarVM/MoarVM/src/gc/worklist.c
Line | Count | Source |
1 | | #include "moar.h" |
2 | | |
3 | | /* Allocates a new GC worklist. */ |
4 | 778 | MVMGCWorklist * MVM_gc_worklist_create(MVMThreadContext *tc, MVMuint8 include_gen2) { |
5 | 778 | MVMGCWorklist *worklist = MVM_malloc(sizeof(MVMGCWorklist)); |
6 | 778 | worklist->items = 0; |
7 | 778 | worklist->alloc = MVM_GC_WORKLIST_START_SIZE; |
8 | 778 | worklist->list = MVM_malloc(worklist->alloc * sizeof(MVMCollectable **)); |
9 | 778 | worklist->include_gen2 = include_gen2; |
10 | 778 | return worklist; |
11 | 778 | } |
12 | | |
13 | | /* Adds an item to the worklist, expanding it if needed. */ |
14 | 230 | void MVM_gc_worklist_add_slow(MVMThreadContext *tc, MVMGCWorklist *worklist, MVMCollectable **item) { |
15 | 230 | if (worklist->items == worklist->alloc) { |
16 | 230 | worklist->alloc *= 2; |
17 | 230 | worklist->list = MVM_realloc(worklist->list, worklist->alloc * sizeof(MVMCollectable **)); |
18 | 230 | } |
19 | 230 | worklist->list[worklist->items++] = item; |
20 | 230 | } |
21 | | |
22 | | /* Pre-sizes the worklist in expectation a certain number of items is about to be |
23 | | * added. */ |
24 | 750 | void MVM_gc_worklist_presize_for(MVMThreadContext *tc, MVMGCWorklist *worklist, MVMint32 items) { |
25 | 750 | if (worklist->items + items >= worklist->alloc) { |
26 | 161 | worklist->alloc = worklist->items + items; |
27 | 161 | worklist->list = MVM_realloc(worklist->list, worklist->alloc * sizeof(MVMCollectable **)); |
28 | 161 | } |
29 | 750 | } |
30 | | |
31 | | /* Free a worklist. */ |
32 | 781 | void MVM_gc_worklist_destroy(MVMThreadContext *tc, MVMGCWorklist *worklist) { |
33 | 781 | MVM_free(worklist->list); |
34 | 781 | MVM_free(worklist); |
35 | 781 | } |