Remove system.setupForeignThreadGc if threads option is off or TLS
emulation is enabled
This commit is contained in:
parent
4c2894ca26
commit
4f8244c717
1 changed files with 22 additions and 12 deletions
|
|
@ -78,19 +78,29 @@ iterator items(stack: ptr GcStack): ptr GcStack =
|
||||||
yield s
|
yield s
|
||||||
s = s.next
|
s = s.next
|
||||||
|
|
||||||
var
|
# There will be problems with GC in foreign threads if `threads` option is off or TLS emulation is enabled
|
||||||
localGcInitialized {.rtlThreadVar.}: bool
|
const allowForeignThreadGc = compileOption("threads") and not compileOption("tlsEmulation")
|
||||||
|
|
||||||
proc setupForeignThreadGc*() =
|
when allowForeignThreadGc:
|
||||||
## call this if you registered a callback that will be run from a thread not
|
var
|
||||||
## under your control. This has a cheap thread-local guard, so the GC for
|
localGcInitialized {.rtlThreadVar.}: bool
|
||||||
## this thread will only be initialized once per thread, no matter how often
|
|
||||||
## it is called.
|
proc setupForeignThreadGc*() =
|
||||||
if not localGcInitialized:
|
## Call this if you registered a callback that will be run from a thread not
|
||||||
localGcInitialized = true
|
## under your control. This has a cheap thread-local guard, so the GC for
|
||||||
var stackTop {.volatile.}: pointer
|
## this thread will only be initialized once per thread, no matter how often
|
||||||
setStackBottom(addr(stackTop))
|
## it is called.
|
||||||
initGC()
|
##
|
||||||
|
## This function is availble only when ``--threads:on`` and ``--tlsEmulation:off``
|
||||||
|
## switches are used
|
||||||
|
if not localGcInitialized:
|
||||||
|
localGcInitialized = true
|
||||||
|
var stackTop {.volatile.}: pointer
|
||||||
|
setStackBottom(addr(stackTop))
|
||||||
|
initGC()
|
||||||
|
else:
|
||||||
|
template setupForeignThreadGc*(): stmt =
|
||||||
|
{.error: "setupForeignThreadGc is availble only when ``--threads:on`` and ``--tlsEmulation:off`` are used".}
|
||||||
|
|
||||||
# ----------------- stack management --------------------------------------
|
# ----------------- stack management --------------------------------------
|
||||||
# inspired from Smart Eiffel
|
# inspired from Smart Eiffel
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue