Remove system.setupForeignThreadGc if threads option is off or TLS

emulation is enabled
This commit is contained in:
Anatoly Galiulin 2016-01-28 12:29:53 +06:00
commit 4f8244c717

View file

@ -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
const allowForeignThreadGc = compileOption("threads") and not compileOption("tlsEmulation")
when allowForeignThreadGc:
var
localGcInitialized {.rtlThreadVar.}: bool localGcInitialized {.rtlThreadVar.}: bool
proc setupForeignThreadGc*() = proc setupForeignThreadGc*() =
## call this if you registered a callback that will be run from a thread not ## 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 ## 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 ## this thread will only be initialized once per thread, no matter how often
## it is called. ## it is called.
##
## This function is availble only when ``--threads:on`` and ``--tlsEmulation:off``
## switches are used
if not localGcInitialized: if not localGcInitialized:
localGcInitialized = true localGcInitialized = true
var stackTop {.volatile.}: pointer var stackTop {.volatile.}: pointer
setStackBottom(addr(stackTop)) setStackBottom(addr(stackTop))
initGC() 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