renamed lock->aquire
This commit is contained in:
parent
adf13aaea3
commit
ee445dc022
2 changed files with 20 additions and 20 deletions
|
|
@ -76,17 +76,17 @@ var
|
||||||
# This is wasteful but safe. This is a lock against recursive garbage
|
# This is wasteful but safe. This is a lock against recursive garbage
|
||||||
# collection, not a lock for threads!
|
# collection, not a lock for threads!
|
||||||
|
|
||||||
proc lock(gch: var TGcHeap) {.inline.} =
|
proc aquire(gch: var TGcHeap) {.inline.} =
|
||||||
when hasThreadSupport:
|
when hasThreadSupport:
|
||||||
if isMultiThreaded:
|
if isMultiThreaded:
|
||||||
Lock(gch.zctLock)
|
aquire(gch.zctLock)
|
||||||
lock(gch.cycleRootsLock)
|
aquire(gch.cycleRootsLock)
|
||||||
|
|
||||||
proc unlock(gch: var TGcHeap) {.inline.} =
|
proc release(gch: var TGcHeap) {.inline.} =
|
||||||
when hasThreadSupport:
|
when hasThreadSupport:
|
||||||
if isMultiThreaded:
|
if isMultiThreaded:
|
||||||
unlock(gch.zctLock)
|
release(gch.zctLock)
|
||||||
unlock(gch.cycleRootsLock)
|
release(gch.cycleRootsLock)
|
||||||
|
|
||||||
proc addZCT(s: var TCellSeq, c: PCell) {.noinline.} =
|
proc addZCT(s: var TCellSeq, c: PCell) {.noinline.} =
|
||||||
if (c.refcount and rcZct) == 0:
|
if (c.refcount and rcZct) == 0:
|
||||||
|
|
@ -205,18 +205,18 @@ proc prepareDealloc(cell: PCell) =
|
||||||
proc rtlAddCycleRoot(c: PCell) {.rtl, inl.} =
|
proc rtlAddCycleRoot(c: PCell) {.rtl, inl.} =
|
||||||
# we MUST access gch as a global here, because this crosses DLL boundaries!
|
# we MUST access gch as a global here, because this crosses DLL boundaries!
|
||||||
when hasThreadSupport:
|
when hasThreadSupport:
|
||||||
if isMultiThreaded: Lock(gch.cycleRootsLock)
|
if isMultiThreaded: Aquire(gch.cycleRootsLock)
|
||||||
incl(gch.cycleRoots, c)
|
incl(gch.cycleRoots, c)
|
||||||
when hasThreadSupport:
|
when hasThreadSupport:
|
||||||
if isMultiThreaded: Unlock(gch.cycleRootsLock)
|
if isMultiThreaded: Release(gch.cycleRootsLock)
|
||||||
|
|
||||||
proc rtlAddZCT(c: PCell) {.rtl, inl.} =
|
proc rtlAddZCT(c: PCell) {.rtl, inl.} =
|
||||||
# we MUST access gch as a global here, because this crosses DLL boundaries!
|
# we MUST access gch as a global here, because this crosses DLL boundaries!
|
||||||
when hasThreadSupport:
|
when hasThreadSupport:
|
||||||
if isMultiThreaded: Lock(gch.zctLock)
|
if isMultiThreaded: Aquire(gch.zctLock)
|
||||||
addZCT(gch.zct, c)
|
addZCT(gch.zct, c)
|
||||||
when hasThreadSupport:
|
when hasThreadSupport:
|
||||||
if isMultiThreaded: Unlock(gch.zctLock)
|
if isMultiThreaded: Release(gch.zctLock)
|
||||||
|
|
||||||
proc decRef(c: PCell) {.inline.} =
|
proc decRef(c: PCell) {.inline.} =
|
||||||
when stressGC:
|
when stressGC:
|
||||||
|
|
@ -333,7 +333,7 @@ proc checkCollection {.inline.} =
|
||||||
|
|
||||||
proc newObj(typ: PNimType, size: int): pointer {.compilerRtl.} =
|
proc newObj(typ: PNimType, size: int): pointer {.compilerRtl.} =
|
||||||
# generates a new object and sets its reference counter to 0
|
# generates a new object and sets its reference counter to 0
|
||||||
lock(gch)
|
aquire(gch)
|
||||||
assert(typ.kind in {tyRef, tyString, tySequence})
|
assert(typ.kind in {tyRef, tyString, tySequence})
|
||||||
checkCollection()
|
checkCollection()
|
||||||
var res = cast[PCell](rawAlloc(allocator, size + sizeof(TCell)))
|
var res = cast[PCell](rawAlloc(allocator, size + sizeof(TCell)))
|
||||||
|
|
@ -362,7 +362,7 @@ proc newObj(typ: PNimType, size: int): pointer {.compilerRtl.} =
|
||||||
add(gch.zct, res)
|
add(gch.zct, res)
|
||||||
when logGC: writeCell("new cell", res)
|
when logGC: writeCell("new cell", res)
|
||||||
gcTrace(res, csAllocated)
|
gcTrace(res, csAllocated)
|
||||||
unlock(gch)
|
release(gch)
|
||||||
result = cellToUsr(res)
|
result = cellToUsr(res)
|
||||||
|
|
||||||
proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.} =
|
proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.} =
|
||||||
|
|
@ -372,7 +372,7 @@ proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.} =
|
||||||
cast[PGenericSeq](result).space = len
|
cast[PGenericSeq](result).space = len
|
||||||
|
|
||||||
proc growObj(old: pointer, newsize: int): pointer {.rtl.} =
|
proc growObj(old: pointer, newsize: int): pointer {.rtl.} =
|
||||||
lock(gch)
|
aquire(gch)
|
||||||
checkCollection()
|
checkCollection()
|
||||||
var ol = usrToCell(old)
|
var ol = usrToCell(old)
|
||||||
assert(ol.typ != nil)
|
assert(ol.typ != nil)
|
||||||
|
|
@ -410,7 +410,7 @@ proc growObj(old: pointer, newsize: int): pointer {.rtl.} =
|
||||||
else:
|
else:
|
||||||
assert(ol.typ != nil)
|
assert(ol.typ != nil)
|
||||||
zeroMem(ol, sizeof(TCell))
|
zeroMem(ol, sizeof(TCell))
|
||||||
unlock(gch)
|
release(gch)
|
||||||
result = cellToUsr(res)
|
result = cellToUsr(res)
|
||||||
|
|
||||||
# ---------------- cycle collector -------------------------------------------
|
# ---------------- cycle collector -------------------------------------------
|
||||||
|
|
@ -679,12 +679,12 @@ when not defined(useNimRtl):
|
||||||
# set to the max value to suppress the cycle detector
|
# set to the max value to suppress the cycle detector
|
||||||
|
|
||||||
proc GC_fullCollect() =
|
proc GC_fullCollect() =
|
||||||
lock(gch)
|
aquire(gch)
|
||||||
var oldThreshold = cycleThreshold
|
var oldThreshold = cycleThreshold
|
||||||
cycleThreshold = 0 # forces cycle collection
|
cycleThreshold = 0 # forces cycle collection
|
||||||
collectCT(gch)
|
collectCT(gch)
|
||||||
cycleThreshold = oldThreshold
|
cycleThreshold = oldThreshold
|
||||||
unlock(gch)
|
release(gch)
|
||||||
|
|
||||||
proc GC_getStatistics(): string =
|
proc GC_getStatistics(): string =
|
||||||
GC_disable()
|
GC_disable()
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,9 @@ when defined(Windows):
|
||||||
|
|
||||||
proc InitLock(L: var TSysLock) {.stdcall,
|
proc InitLock(L: var TSysLock) {.stdcall,
|
||||||
dynlib: "kernel32", importc: "InitializeCriticalSection".}
|
dynlib: "kernel32", importc: "InitializeCriticalSection".}
|
||||||
proc Lock(L: var TSysLock) {.stdcall,
|
proc Aquire(L: var TSysLock) {.stdcall,
|
||||||
dynlib: "kernel32", importc: "EnterCriticalSection".}
|
dynlib: "kernel32", importc: "EnterCriticalSection".}
|
||||||
proc Unlock(L: var TSysLock) {.stdcall,
|
proc Release(L: var TSysLock) {.stdcall,
|
||||||
dynlib: "kernel32", importc: "LeaveCriticalSection".}
|
dynlib: "kernel32", importc: "LeaveCriticalSection".}
|
||||||
|
|
||||||
proc CreateThread(lpThreadAttributes: Pointer, dwStackSize: int32,
|
proc CreateThread(lpThreadAttributes: Pointer, dwStackSize: int32,
|
||||||
|
|
@ -76,9 +76,9 @@ else:
|
||||||
|
|
||||||
proc InitLock(L: var TSysLock, attr: pointer = nil) {.
|
proc InitLock(L: var TSysLock, attr: pointer = nil) {.
|
||||||
importc: "pthread_mutex_init", header: "<pthread.h>".}
|
importc: "pthread_mutex_init", header: "<pthread.h>".}
|
||||||
proc Lock(L: var TSysLock) {.
|
proc Aquire(L: var TSysLock) {.
|
||||||
importc: "pthread_mutex_lock", header: "<pthread.h>".}
|
importc: "pthread_mutex_lock", header: "<pthread.h>".}
|
||||||
proc Unlock(L: var TSysLock) {.
|
proc Release(L: var TSysLock) {.
|
||||||
importc: "pthread_mutex_unlock", header: "<pthread.h>".}
|
importc: "pthread_mutex_unlock", header: "<pthread.h>".}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue