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:
parent
f9d8d6ce09
commit
70ce8695e7
1 changed files with 11 additions and 16 deletions
|
|
@ -196,14 +196,21 @@ type
|
||||||
nil
|
nil
|
||||||
{.deprecated: [TThreadLocalStorage: ThreadLocalStorage, TGcThread: GcThread].}
|
{.deprecated: [TThreadLocalStorage: ThreadLocalStorage, TGcThread: GcThread].}
|
||||||
|
|
||||||
|
when not defined(useNimRtl):
|
||||||
|
when not useStackMaskHack:
|
||||||
|
var mainThread: GcThread
|
||||||
|
|
||||||
|
#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
|
# 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
|
# thread storage slot, but to rely on the implementation to assign slot X
|
||||||
# for us... ;-)
|
# for us... ;-)
|
||||||
var globalsSlot: ThreadVarSlot
|
var globalsSlot: ThreadVarSlot
|
||||||
|
|
||||||
when not defined(useNimRtl):
|
proc GetThreadLocalVars(): pointer {.compilerRtl, inl.} =
|
||||||
when not useStackMaskHack:
|
result = addr(cast[PGcThread](threadVarGetValue(globalsSlot)).tls)
|
||||||
var mainThread: GcThread
|
|
||||||
|
|
||||||
proc initThreadVarsEmulation() {.compilerProc, inline.} =
|
proc initThreadVarsEmulation() {.compilerProc, inline.} =
|
||||||
when not defined(useNimRtl):
|
when not defined(useNimRtl):
|
||||||
|
|
@ -211,13 +218,6 @@ proc initThreadVarsEmulation() {.compilerProc, inline.} =
|
||||||
when declared(mainThread):
|
when declared(mainThread):
|
||||||
threadVarSetValue(globalsSlot, addr(mainThread))
|
threadVarSetValue(globalsSlot, addr(mainThread))
|
||||||
|
|
||||||
#const globalsSlot = ThreadVarSlot(0)
|
|
||||||
#sysAssert checkSlot.int == globalsSlot.int
|
|
||||||
|
|
||||||
when emulatedThreadVars:
|
|
||||||
proc GetThreadLocalVars(): pointer {.compilerRtl, inl.} =
|
|
||||||
result = addr(cast[PGcThread](threadVarGetValue(globalsSlot)).tls)
|
|
||||||
|
|
||||||
when useStackMaskHack:
|
when useStackMaskHack:
|
||||||
proc maskStackPointer(offset: int): pointer {.compilerRtl, inl.} =
|
proc maskStackPointer(offset: int): pointer {.compilerRtl, inl.} =
|
||||||
var x {.volatile.}: pointer
|
var x {.volatile.}: pointer
|
||||||
|
|
@ -398,11 +398,6 @@ proc threadId*[TArg](t: var Thread[TArg]): ThreadId[TArg] {.inline.} =
|
||||||
## returns the thread ID of `t`.
|
## returns the thread ID of `t`.
|
||||||
result = addr(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:
|
when false:
|
||||||
proc mainThreadId*[TArg](): ThreadId[TArg] =
|
proc mainThreadId*[TArg](): ThreadId[TArg] =
|
||||||
## returns the thread ID of the main thread.
|
## returns the thread ID of the main thread.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue