Merge pull request #2995 from avsej/fix-tls-dlopen-issue

Fix #2672. Do not define globalsSlot for native TLS
This commit is contained in:
Andreas Rumpf 2015-06-26 10:24:04 +02:00
commit 17f96b9861
3 changed files with 53 additions and 60 deletions

View file

@ -147,4 +147,3 @@ else:
{.error: "no implementation for dyncalls".} {.error: "no implementation for dyncalls".}
{.pop.} {.pop.}

View file

@ -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.
@ -413,4 +408,3 @@ when useStackMaskHack:
var mainThread: Thread[pointer] var mainThread: Thread[pointer]
createThread(mainThread, tp) createThread(mainThread, tp)
joinThread(mainThread) joinThread(mainThread)