mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 14:55:24 +00:00
bugfix: init of temps
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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.} =
|
||||
|
||||
@@ -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
0
lib/wrappers/expat.nim
Normal file → Executable file
Reference in New Issue
Block a user