mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-21 16:31:39 +00:00
added 'setupGcForForeignThread' for better C interop
This commit is contained in:
@@ -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.}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user