added 'setupGcForForeignThread' for better C interop

This commit is contained in:
Araq
2014-12-11 23:29:26 +01:00
parent 50e156db6e
commit 5a52e941b5
2 changed files with 28 additions and 0 deletions

View File

@@ -292,6 +292,20 @@ proc initGC() =
when useMarkForDebug or useBackupGc:
init(gch.marked)
var
localGcInitialized {.rtlThreadVar.}: bool
proc setupForeignThreadGc*() =
## call this if you registered a callback that will be run from a thread not
## under your control. This has a cheap thread-local guard, so the GC for
## this thread will only be initialized once per thread, no matter how often
## it is called.
if not localGcInitialized:
localGcInitialized = true
var stackTop {.volatile.}: pointer
setStackBottom(addr(stackTop))
initGC()
when useMarkForDebug or useBackupGc:
type
TGlobalMarkerProc = proc () {.nimcall, benign.}

View File

@@ -168,6 +168,20 @@ proc initGC() =
Init(gch.allocated)
init(gch.marked)
var
localGcInitialized {.rtlThreadVar.}: bool
proc setupForeignThreadGc*() =
## call this if you registered a callback that will be run from a thread not
## under your control. This has a cheap thread-local guard, so the GC for
## this thread will only be initialized once per thread, no matter how often
## it is called.
if not localGcInitialized:
localGcInitialized = true
var stackTop {.volatile.}: pointer
setStackBottom(addr(stackTop))
initGC()
proc forAllSlotsAux(dest: pointer, n: ptr TNimNode, op: TWalkOp) {.benign.} =
var d = cast[ByteAddress](dest)
case n.kind