bugfix: init of temps

This commit is contained in:
Araq
2010-08-24 00:19:16 +02:00
parent b1ca3ab7c5
commit e439c6b02e
15 changed files with 107 additions and 76 deletions

View File

@@ -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

View File

@@ -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:

View File

@@ -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 =

View File

@@ -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.} =

View File

@@ -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

0
lib/wrappers/expat.nim Normal file → Executable file
View File