Skip to content

Commit e37c6c7

Browse files
Fix issue with GC'd pointers in RingQueue
1 parent bfc2a8d commit e37c6c7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/photon/ds/ring_queue.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import core.atomic;
44
import core.internal.spinlock;
55
import core.stdc.stdlib;
66
import core.lifetime;
7+
import core.memory;
8+
import std.traits;
79

810
import photon.exceptions;
911

@@ -21,6 +23,9 @@ struct RingQueue(T, Event)
2123
this(size_t capacity, Event cts, Event rtr)
2224
{
2325
store = cast(T*)malloc(T.sizeof * capacity);
26+
static if (hasIndirections!T) {
27+
GC.addRange(store, T.sizeof * capacity);
28+
}
2429
length = capacity;
2530
size = 0;
2631
fetch = insert = 0;
@@ -114,6 +119,9 @@ auto allocRingQueue(T, Event)(size_t capacity, Event cts, Event rtr){
114119
}
115120

116121
void disposeRingQueue(T, Event)(RingQueue!(T, Event)* q) {
122+
static if (hasIndirections!T) {
123+
GC.removeRange(q.store);
124+
}
117125
free(q.store);
118126
free(q);
119127
}

0 commit comments

Comments
 (0)