summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2010-08-24 00:19:16 +0200
committerAraq <rumpf_a@web.de>2010-08-24 00:19:16 +0200
commite439c6b02e62837e1387e339d72fca91afd3981a (patch)
treee2b03747c77e8d7d05d7b0a947d4693dc78ee9ac /lib
parentb1ca3ab7c517e5e6b1b9f549e3572c84dad77fb3 (diff)
downloadNim-e439c6b02e62837e1387e339d72fca91afd3981a.tar.gz
bugfix: init of temps
Diffstat (limited to 'lib')
-rwxr-xr-xlib/nimbase.h11
-rwxr-xr-xlib/pure/json.nim2
-rwxr-xr-xlib/pure/strtabs.nim2
-rwxr-xr-xlib/system.nim6
-rwxr-xr-xlib/system/systhread.nim26
-rwxr-xr-x[-rw-r--r--]lib/wrappers/expat.nim0
6 files changed, 46 insertions, 1 deletions
diff --git a/lib/nimbase.h b/lib/nimbase.h
index 5bc644dc9..01c3ece20 100755
--- a/lib/nimbase.h
+++ b/lib/nimbase.h
@@ -433,4 +433,15 @@ struct NimException {
 
 #define NIM_POSIX_INIT  __attribute__((constructor)) 
 
+
+#if defined(_MSCVER) && defined(__i386__)
+__declspec(naked) int __fastcall NimXadd(volatile int* pNum, int val) {
+  __asm {
+    lock xadd dword ptr [ECX], EDX
+    mov EAX, EDX
+    ret
+  }
+}
+#endif
+
 #endif
diff --git a/lib/pure/json.nim b/lib/pure/json.nim
index bc52fb886..0fd2a9f01 100755
--- a/lib/pure/json.nim
+++ b/lib/pure/json.nim
@@ -345,6 +345,8 @@ proc next*(my: var TJsonParser) =
   ## retrieves the first/next event. This controls the parser.
   var tk = getTok(my)
   var i = my.state.len-1
+  # the following code is a state machine. If we had proper coroutines,
+  # the code could be much simpler.
   case my.state[i]
   of stateEof:
     if tk == tkEof:
diff --git a/lib/pure/strtabs.nim b/lib/pure/strtabs.nim
index 9779be5ff..1ac8930b0 100755
--- a/lib/pure/strtabs.nim
+++ b/lib/pure/strtabs.nim
@@ -73,7 +73,7 @@ proc mustRehash(length, counter: int): bool =
   assert(length > counter)
   result = (length * 2 < counter * 3) or (length - counter < 4)
 
-proc nextTry(h, maxHash: THash): THash =
+proc nextTry(h, maxHash: THash): THash {.inline.} =
   result = ((5 * h) + 1) and maxHash
 
 proc RawGet(t: PStringTable, key: string): int =
diff --git a/lib/system.nim b/lib/system.nim
index 626002794..0152ebf23 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1303,6 +1303,12 @@ 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 initStackBottom() {.inline.} = 
diff --git a/lib/system/systhread.nim b/lib/system/systhread.nim
index 611191e70..68121661f 100755
--- a/lib/system/systhread.nim
+++ b/lib/system/systhread.nim
@@ -7,9 +7,35 @@
 #    distribution, for details about the copyright.
 #
 
+when defined(gcc) or defined(llvm_gcc):
+  proc sync_add_and_fetch(p: var int, val: int): int {.
+    importc: "__sync_add_and_fetch", nodecl.}
+  proc sync_sub_and_fetch(p: var int, val: int): int {.
+    importc: "__sync_sub_and_fetch", nodecl.}
+elif defined(vcc):
+  proc sync_add_and_fetch(p: var int, val: int): int {.
+    importc: "NimXadd", nodecl.}
+
 const
   isMultiThreaded* = true
   maxThreads = 256
+
+proc atomicInc(memLoc: var int, x: int): int =
+  when isMultiThreaded:
+    result = sync_add_and_fetch(memLoc, x)
+  else:
+    inc(memLoc, x)
+    result = memLoc
+  
+proc atomicDec(memLoc: var int, x: int): int =
+  when isMultiThreaded:
+    when defined(sync_sub_and_fetch):
+      result = sync_sub_and_fetch(memLoc, x)
+    else:
+      result = sync_add_and_fetch(memLoc, -x)
+  else:
+    dec(memLoc, x)
+    result = memLoc  
   
 type
   TThread* {.final, pure.} = object
diff --git a/lib/wrappers/expat.nim b/lib/wrappers/expat.nim
index 59e698263..59e698263 100644..100755
--- a/lib/wrappers/expat.nim
+++ b/lib/wrappers/expat.nim