summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-05-09 22:29:29 +0200
committerAraq <rumpf_a@web.de>2011-05-09 22:29:29 +0200
commitf717f1e628782cc54a69ce589249d694a77015bb (patch)
treefc6346759e2a5b039f6a5333f5774baf7e81366c /lib/system
parentd2e2d71d05b9a8381bf7fef7bb23da029e576c2a (diff)
downloadNim-f717f1e628782cc54a69ce589249d694a77015bb.tar.gz
threadvar alternative
Diffstat (limited to 'lib/system')
-rwxr-xr-xlib/system/cgprocs.nim14
-rwxr-xr-xlib/system/excpt.nim2
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/system/cgprocs.nim b/lib/system/cgprocs.nim
index f77768a7a..3bc3176a8 100755
--- a/lib/system/cgprocs.nim
+++ b/lib/system/cgprocs.nim
@@ -37,9 +37,11 @@ when defined(windows):
   
   proc ThreadVarAlloc(): TThreadVarSlot {.compilerproc, inline.} =
     result = TlsAlloc()
-  proc ThreadVarSetValue(s: TThreadVarSlot, value: pointer) {.compilerproc.} =
+  proc ThreadVarSetValue(s: TThreadVarSlot, value: pointer) {.
+                         compilerproc, inline.} =
     TlsSetValue(s, value)
-  proc ThreadVarGetValue(s: TThreadVarSlot): pointer {.compilerproc.} =
+  proc ThreadVarGetValue(s: TThreadVarSlot): pointer {.
+                         compilerproc, inline.} =
     result = TlsGetValue(s)
   
 else:
@@ -58,4 +60,12 @@ else:
 
   proc pthread_setspecific(a1: Tpthread_key, a2: pointer): int32 {.
     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)
 
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index 073013113..1a9816aed 100755
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -39,6 +39,8 @@ type
     exc: ref E_Base  # XXX only needed for bootstrapping; unused
     context: C_JmpBuf
 
+when hasThreadSupport: nil
+
 var
   excHandler {.threadvar, compilerproc.}: PSafePoint = nil
     # list of exception handlers