made --newruntime ready for multi-threading
This commit is contained in:
parent
bb5ca0772e
commit
416ba133ad
1 changed files with 21 additions and 5 deletions
|
|
@ -52,17 +52,30 @@ proc nimNewObj(size: int): pointer {.compilerRtl.} =
|
||||||
result = orig +! sizeof(RefHeader)
|
result = orig +! sizeof(RefHeader)
|
||||||
else:
|
else:
|
||||||
result = alloc0(s) +! sizeof(RefHeader)
|
result = alloc0(s) +! sizeof(RefHeader)
|
||||||
|
when hasThreadSupport:
|
||||||
|
atomicInc allocs
|
||||||
|
else:
|
||||||
inc allocs
|
inc allocs
|
||||||
|
|
||||||
proc nimDecWeakRef(p: pointer) {.compilerRtl.} =
|
proc nimDecWeakRef(p: pointer) {.compilerRtl.} =
|
||||||
|
when hasThreadSupport:
|
||||||
|
atomicDec head(p).rc
|
||||||
|
else:
|
||||||
dec head(p).rc
|
dec head(p).rc
|
||||||
|
|
||||||
proc nimIncWeakRef(p: pointer) {.compilerRtl.} =
|
proc nimIncWeakRef(p: pointer) {.compilerRtl.} =
|
||||||
|
when hasThreadSupport:
|
||||||
|
atomicInc head(p).rc
|
||||||
|
else:
|
||||||
inc head(p).rc
|
inc head(p).rc
|
||||||
|
|
||||||
proc nimRawDispose(p: pointer) {.compilerRtl.} =
|
proc nimRawDispose(p: pointer) {.compilerRtl.} =
|
||||||
when not defined(nimscript):
|
when not defined(nimscript):
|
||||||
if head(p).rc != 0:
|
when hasThreadSupport:
|
||||||
|
let hasDanglingRefs = atomicLoadN(addr head(p).rc, ATOMIC_RELAXED) != 0
|
||||||
|
else:
|
||||||
|
let hasDanglingRefs = head(p).rc != 0
|
||||||
|
if hasDanglingRefs:
|
||||||
cstderr.rawWrite "[FATAL] dangling references exist\n"
|
cstderr.rawWrite "[FATAL] dangling references exist\n"
|
||||||
quit 1
|
quit 1
|
||||||
when defined(useMalloc):
|
when defined(useMalloc):
|
||||||
|
|
@ -70,6 +83,9 @@ proc nimRawDispose(p: pointer) {.compilerRtl.} =
|
||||||
else:
|
else:
|
||||||
dealloc(p -! sizeof(RefHeader))
|
dealloc(p -! sizeof(RefHeader))
|
||||||
if allocs > 0:
|
if allocs > 0:
|
||||||
|
when hasThreadSupport:
|
||||||
|
atomicDec allocs
|
||||||
|
else:
|
||||||
dec allocs
|
dec allocs
|
||||||
else:
|
else:
|
||||||
cstderr.rawWrite "[FATAL] unpaired dealloc\n"
|
cstderr.rawWrite "[FATAL] unpaired dealloc\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue