cycle collector: make it threadsafe

This commit is contained in:
Araq
2020-05-12 20:12:55 +02:00
parent 09ea8f9cf8
commit 82f008158c

View File

@@ -89,15 +89,15 @@ proc nimTraceRefDyn(q: pointer; env: pointer) {.compilerRtl.} =
j.traceStack.add(head p[], cast[ptr PNimType](p[])[])
var
roots: CellSeq
roots {.threadvar.}: CellSeq
proc unregisterCycle(s: Cell) =
# swap with the last element. O(1)
let idx = s.rootIdx
if idx >= roots.len or idx < 0:
cprintf("[Bug!] %ld\n", idx)
quit 1
when false:
if idx >= roots.len or idx < 0:
cprintf("[Bug!] %ld\n", idx)
quit 1
roots.d[idx] = roots.d[roots.len-1]
roots.d[idx][0].rootIdx = idx
dec roots.len