diff options
-rw-r--r-- | lib/system/threads.nim | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/lib/system/threads.nim b/lib/system/threads.nim index 1ec9aadf1..180e0410b 100644 --- a/lib/system/threads.nim +++ b/lib/system/threads.nim @@ -196,28 +196,28 @@ type nil {.deprecated: [TThreadLocalStorage: ThreadLocalStorage, TGcThread: GcThread].} -# XXX it'd be more efficient to not use a global variable for the -# thread storage slot, but to rely on the implementation to assign slot X -# for us... ;-) -var globalsSlot: ThreadVarSlot - when not defined(useNimRtl): when not useStackMaskHack: var mainThread: GcThread -proc initThreadVarsEmulation() {.compilerProc, inline.} = - when not defined(useNimRtl): - globalsSlot = threadVarAlloc() - when declared(mainThread): - threadVarSetValue(globalsSlot, addr(mainThread)) - #const globalsSlot = ThreadVarSlot(0) #sysAssert checkSlot.int == globalsSlot.int when emulatedThreadVars: + # XXX it'd be more efficient to not use a global variable for the + # thread storage slot, but to rely on the implementation to assign slot X + # for us... ;-) + var globalsSlot: ThreadVarSlot + proc GetThreadLocalVars(): pointer {.compilerRtl, inl.} = result = addr(cast[PGcThread](threadVarGetValue(globalsSlot)).tls) + proc initThreadVarsEmulation() {.compilerProc, inline.} = + when not defined(useNimRtl): + globalsSlot = threadVarAlloc() + when declared(mainThread): + threadVarSetValue(globalsSlot, addr(mainThread)) + when useStackMaskHack: proc maskStackPointer(offset: int): pointer {.compilerRtl, inl.} = var x {.volatile.}: pointer @@ -398,11 +398,6 @@ proc threadId*[TArg](t: var Thread[TArg]): ThreadId[TArg] {.inline.} = ## returns the thread ID of `t`. result = addr(t) -proc myThreadId*[TArg](): ThreadId[TArg] = - ## returns the thread ID of the thread that calls this proc. This is unsafe - ## because the type ``TArg`` is not checked for consistency! - result = cast[ThreadId[TArg]](threadVarGetValue(globalsSlot)) - when false: proc mainThreadId*[TArg](): ThreadId[TArg] = ## returns the thread ID of the main thread. |