summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-02-26 02:04:06 +0100
committerAraq <rumpf_a@web.de>2015-02-26 02:05:23 +0100
commit3dd1ecbae4a08627ec619d3abd6ee1f7f24455a6 (patch)
treeec4eb8a89641915d983190389c5b2ad070c4fcee
parent9053799bf57df4043923b5635806185cf997428e (diff)
downloadNim-3dd1ecbae4a08627ec619d3abd6ee1f7f24455a6.tar.gz
fixes #2074
-rw-r--r--lib/system/threads.nim12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/system/threads.nim b/lib/system/threads.nim
index 4e0720007..81d9e5d73 100644
--- a/lib/system/threads.nim
+++ b/lib/system/threads.nim
@@ -84,8 +84,18 @@ when defined(windows):
       importc: "TlsAlloc", stdcall, header: "<windows.h>".}
     proc threadVarSetValue(dwTlsIndex: TThreadVarSlot, lpTlsValue: pointer) {.
       importc: "TlsSetValue", stdcall, header: "<windows.h>".}
-    proc threadVarGetValue(dwTlsIndex: TThreadVarSlot): pointer {.
+    proc tlsGetValue(dwTlsIndex: TThreadVarSlot): pointer {.
       importc: "TlsGetValue", stdcall, header: "<windows.h>".}
+
+    proc getLastError(): uint32 {.
+      importc: "GetLastError", stdcall, header: "<windows.h>".}
+    proc setLastError(x: uint32) {.
+      importc: "SetLastError", stdcall, header: "<windows.h>".}
+
+    proc threadVarGetValue(dwTlsIndex: TThreadVarSlot): pointer =
+      let realLastError = getLastError()
+      result = tlsGetValue(dwTlsIndex)
+      setLastError(realLastError)
   else:
     proc threadVarAlloc(): TThreadVarSlot {.
       importc: "TlsAlloc", stdcall, dynlib: "kernel32".}