cycle collector: make it threadsafe
This commit is contained in:
parent
09ea8f9cf8
commit
82f008158c
1 changed files with 5 additions and 5 deletions
|
|
@ -89,15 +89,15 @@ proc nimTraceRefDyn(q: pointer; env: pointer) {.compilerRtl.} =
|
||||||
j.traceStack.add(head p[], cast[ptr PNimType](p[])[])
|
j.traceStack.add(head p[], cast[ptr PNimType](p[])[])
|
||||||
|
|
||||||
var
|
var
|
||||||
roots: CellSeq
|
roots {.threadvar.}: CellSeq
|
||||||
|
|
||||||
proc unregisterCycle(s: Cell) =
|
proc unregisterCycle(s: Cell) =
|
||||||
# swap with the last element. O(1)
|
# swap with the last element. O(1)
|
||||||
let idx = s.rootIdx
|
let idx = s.rootIdx
|
||||||
|
when false:
|
||||||
if idx >= roots.len or idx < 0:
|
if idx >= roots.len or idx < 0:
|
||||||
cprintf("[Bug!] %ld\n", idx)
|
cprintf("[Bug!] %ld\n", idx)
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
roots.d[idx] = roots.d[roots.len-1]
|
roots.d[idx] = roots.d[roots.len-1]
|
||||||
roots.d[idx][0].rootIdx = idx
|
roots.d[idx][0].rootIdx = idx
|
||||||
dec roots.len
|
dec roots.len
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue