added 'setupGcForForeignThread' for better C interop
This commit is contained in:
parent
50e156db6e
commit
5a52e941b5
2 changed files with 28 additions and 0 deletions
|
|
@ -292,6 +292,20 @@ proc initGC() =
|
||||||
when useMarkForDebug or useBackupGc:
|
when useMarkForDebug or useBackupGc:
|
||||||
init(gch.marked)
|
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:
|
when useMarkForDebug or useBackupGc:
|
||||||
type
|
type
|
||||||
TGlobalMarkerProc = proc () {.nimcall, benign.}
|
TGlobalMarkerProc = proc () {.nimcall, benign.}
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,20 @@ proc initGC() =
|
||||||
Init(gch.allocated)
|
Init(gch.allocated)
|
||||||
init(gch.marked)
|
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.} =
|
proc forAllSlotsAux(dest: pointer, n: ptr TNimNode, op: TWalkOp) {.benign.} =
|
||||||
var d = cast[ByteAddress](dest)
|
var d = cast[ByteAddress](dest)
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue