GC improvements; distinguish between thread local and globals in the marking step

This commit is contained in:
Araq 2018-01-14 17:34:27 +01:00
commit f71f9f83c2
8 changed files with 129 additions and 128 deletions

View file

@ -393,3 +393,27 @@ proc deallocHeap*(runFinalizers = true; allowGcAfterwards = true) =
zeroMem(addr gch.region, sizeof(gch.region))
if allowGcAfterwards:
initGC()
type
GlobalMarkerProc = proc () {.nimcall, benign.}
var
globalMarkersLen: int
globalMarkers: array[0.. 3499, GlobalMarkerProc]
threadLocalMarkersLen: int
threadLocalMarkers: array[0.. 3499, GlobalMarkerProc]
proc nimRegisterGlobalMarker(markerProc: GlobalMarkerProc) {.compilerProc.} =
if globalMarkersLen <= high(globalMarkers):
globalMarkers[globalMarkersLen] = markerProc
inc globalMarkersLen
else:
echo "[GC] cannot register global variable; too many global variables"
quit 1
proc nimRegisterThreadLocalMarker(markerProc: GlobalMarkerProc) {.compilerProc.} =
if threadLocalMarkersLen <= high(threadLocalMarkers):
threadLocalMarkers[threadLocalMarkersLen] = markerProc
inc threadLocalMarkersLen
else:
echo "[GC] cannot register thread local variable; too many thread local variables"
quit 1