mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-21 08:21:32 +00:00
Fix #2672. Do not define globalsSlot for native TLS
Motivation ---------- globalsSlot is always defined so threading code works incorrectly when native TLS supported. Modification ------------ Defined globalsSlot only in TLS emulation mode. Remove myThreadId, which based on broken behavior. It might be reimplemented later Result ------ No segfaults.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user