store a pointer to thread local storage to make the GC happy
This commit is contained in:
parent
67a30d8371
commit
6dd8c85051
2 changed files with 5 additions and 4 deletions
|
|
@ -160,9 +160,9 @@ else:
|
||||||
type
|
type
|
||||||
TThread* {.pure, final.}[TParam] = object ## Nimrod thread.
|
TThread* {.pure, final.}[TParam] = object ## Nimrod thread.
|
||||||
sys: TSysThread
|
sys: TSysThread
|
||||||
|
globals: pointer # this allows the GC to track thread local storage!
|
||||||
c: TThreadProcClosure[TParam]
|
c: TThreadProcClosure[TParam]
|
||||||
|
|
||||||
|
|
||||||
when nodeadlocks:
|
when nodeadlocks:
|
||||||
var
|
var
|
||||||
lockList {.threadvar.}: ptr TLock
|
lockList {.threadvar.}: ptr TLock
|
||||||
|
|
@ -283,7 +283,7 @@ proc createThread*[TParam](t: var TThread[TParam],
|
||||||
## proc `tp`. `param` is passed to `tp`.
|
## proc `tp`. `param` is passed to `tp`.
|
||||||
t.c.data = param
|
t.c.data = param
|
||||||
t.c.fn = tp
|
t.c.fn = tp
|
||||||
CreateThreadLocalStorage()
|
t.globals = CreateThreadLocalStorage()
|
||||||
when hostOS == "windows":
|
when hostOS == "windows":
|
||||||
var dummyThreadId: int32
|
var dummyThreadId: int32
|
||||||
t.sys = CreateThread(nil, 0'i32, threadProcWrapper[TParam],
|
t.sys = CreateThread(nil, 0'i32, threadProcWrapper[TParam],
|
||||||
|
|
|
||||||
|
|
@ -106,9 +106,10 @@ when hasThreadSupport:
|
||||||
PGlobals = ptr TGlobals
|
PGlobals = ptr TGlobals
|
||||||
|
|
||||||
var globalsSlot = ThreadVarAlloc()
|
var globalsSlot = ThreadVarAlloc()
|
||||||
proc CreateThreadLocalStorage*() {.inl.} =
|
proc CreateThreadLocalStorage*(): pointer {.inl.} =
|
||||||
isMultiThreaded = true
|
isMultiThreaded = true
|
||||||
ThreadVarSetValue(globalsSlot, alloc0(sizeof(TGlobals)))
|
result = alloc0(sizeof(TGlobals))
|
||||||
|
ThreadVarSetValue(globalsSlot, result)
|
||||||
|
|
||||||
proc GetGlobals(): PGlobals {.compilerRtl, inl.} =
|
proc GetGlobals(): PGlobals {.compilerRtl, inl.} =
|
||||||
result = cast[PGlobals](ThreadVarGetValue(globalsSlot))
|
result = cast[PGlobals](ThreadVarGetValue(globalsSlot))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue