threadvar alternative

This commit is contained in:
Araq 2011-05-09 22:29:29 +02:00
commit f717f1e628
4 changed files with 24 additions and 10 deletions

View file

@ -779,6 +779,14 @@ proc compileOption*(option, arg: string): bool {.
include "system/inclrtl" include "system/inclrtl"
when not defined(ecmascript) and not defined(nimrodVm): when not defined(ecmascript) and not defined(nimrodVm):
proc atomicInc*(memLoc: var int, x: int): int {.inline.}
## atomic increment of `memLoc`. Returns the value after the operation.
proc atomicDec*(memLoc: var int, x: int): int {.inline.}
## atomic decrement of `memLoc`. Returns the value after the operation.
include "system/systhread"
include "system/cgprocs" include "system/cgprocs"
proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.} proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.}
@ -1436,12 +1444,6 @@ proc quit*(errorcode: int = QuitSuccess) {.
when not defined(EcmaScript) and not defined(NimrodVM): when not defined(EcmaScript) and not defined(NimrodVM):
proc atomicInc*(memLoc: var int, x: int): int {.inline.}
## atomic increment of `memLoc`. Returns the value after the operation.
proc atomicDec*(memLoc: var int, x: int): int {.inline.}
## atomic decrement of `memLoc`. Returns the value after the operation.
proc initGC() proc initGC()
proc initStackBottom() {.inline.} = proc initStackBottom() {.inline.} =
@ -1707,7 +1709,7 @@ when not defined(EcmaScript) and not defined(NimrodVM):
else: else:
result = n.sons[n.len] result = n.sons[n.len]
include "system/systhread" #include "system/systhread"
include "system/mmdisp" include "system/mmdisp"
include "system/sysstr" include "system/sysstr"
include "system/assign" include "system/assign"

View file

@ -37,9 +37,11 @@ when defined(windows):
proc ThreadVarAlloc(): TThreadVarSlot {.compilerproc, inline.} = proc ThreadVarAlloc(): TThreadVarSlot {.compilerproc, inline.} =
result = TlsAlloc() result = TlsAlloc()
proc ThreadVarSetValue(s: TThreadVarSlot, value: pointer) {.compilerproc.} = proc ThreadVarSetValue(s: TThreadVarSlot, value: pointer) {.
compilerproc, inline.} =
TlsSetValue(s, value) TlsSetValue(s, value)
proc ThreadVarGetValue(s: TThreadVarSlot): pointer {.compilerproc.} = proc ThreadVarGetValue(s: TThreadVarSlot): pointer {.
compilerproc, inline.} =
result = TlsGetValue(s) result = TlsGetValue(s)
else: else:
@ -58,4 +60,12 @@ else:
proc pthread_setspecific(a1: Tpthread_key, a2: pointer): int32 {. proc pthread_setspecific(a1: Tpthread_key, a2: pointer): int32 {.
importc: "pthread_setspecific", header: "<pthread.h>".} importc: "pthread_setspecific", header: "<pthread.h>".}
proc ThreadVarAlloc(): TThreadVarSlot {.compilerproc, inline.} =
discard pthread_key_create(addr(result), nil)
proc ThreadVarSetValue(s: TThreadVarSlot, value: pointer) {.
compilerproc, inline.} =
discard pthread_setspecific(s, value)
proc ThreadVarGetValue(s: TThreadVarSlot): pointer {.compilerproc, inline.} =
result = pthread_getspecific(s)

View file

@ -39,6 +39,8 @@ type
exc: ref E_Base # XXX only needed for bootstrapping; unused exc: ref E_Base # XXX only needed for bootstrapping; unused
context: C_JmpBuf context: C_JmpBuf
when hasThreadSupport: nil
var var
excHandler {.threadvar, compilerproc.}: PSafePoint = nil excHandler {.threadvar, compilerproc.}: PSafePoint = nil
# list of exception handlers # list of exception handlers

View file

@ -1,6 +1,6 @@
* thread support: threadvar on Windows seems broken; * thread support: threadvar on Windows seems broken;
add --deadlock_prevention:on|off switch add --deadlock_prevention:on|off switch
- implicit ref/ptr->var conversion * implicit ref/ptr->var conversion
High priority (version 0.9.0) High priority (version 0.9.0)