parent
a7cae2bda2
commit
f46569bafd
1 changed files with 36 additions and 10 deletions
|
|
@ -1053,22 +1053,48 @@ template instantiateForRegion(allocator: untyped) {.dirty.} =
|
||||||
inc(result, it.size)
|
inc(result, it.size)
|
||||||
it = it.next
|
it = it.next
|
||||||
|
|
||||||
proc getFreeMem(): int =
|
when hasThreadSupport:
|
||||||
result = allocator.freeMem
|
var sharedHeap: MemRegion
|
||||||
#sysAssert(result == countFreeMem())
|
var heapLock: SysLock
|
||||||
|
initSysLock(heapLock)
|
||||||
|
|
||||||
proc getTotalMem(): int = return allocator.currMem
|
proc getFreeMem(): int =
|
||||||
proc getOccupiedMem(): int = return allocator.occ #getTotalMem() - getFreeMem()
|
#sysAssert(result == countFreeMem())
|
||||||
proc getMaxMem*(): int = return getMaxMem(allocator)
|
when hasThreadSupport and defined(gcDestructors):
|
||||||
|
acquireSys(heapLock)
|
||||||
|
result = sharedHeap.freeMem
|
||||||
|
releaseSys(heapLock)
|
||||||
|
else:
|
||||||
|
result = allocator.freeMem
|
||||||
|
|
||||||
|
proc getTotalMem(): int =
|
||||||
|
when hasThreadSupport and defined(gcDestructors):
|
||||||
|
acquireSys(heapLock)
|
||||||
|
result = sharedHeap.currMem
|
||||||
|
releaseSys(heapLock)
|
||||||
|
else:
|
||||||
|
result = allocator.currMem
|
||||||
|
|
||||||
|
proc getOccupiedMem(): int =
|
||||||
|
when hasThreadSupport and defined(gcDestructors):
|
||||||
|
acquireSys(heapLock)
|
||||||
|
result = sharedHeap.occ
|
||||||
|
releaseSys(heapLock)
|
||||||
|
else:
|
||||||
|
result = allocator.occ #getTotalMem() - getFreeMem()
|
||||||
|
|
||||||
|
proc getMaxMem*(): int =
|
||||||
|
when hasThreadSupport and defined(gcDestructors):
|
||||||
|
acquireSys(heapLock)
|
||||||
|
result = getMaxMem(sharedHeap)
|
||||||
|
releaseSys(heapLock)
|
||||||
|
else:
|
||||||
|
result = getMaxMem(allocator)
|
||||||
|
|
||||||
when defined(nimTypeNames):
|
when defined(nimTypeNames):
|
||||||
proc getMemCounters*(): (int, int) = getMemCounters(allocator)
|
proc getMemCounters*(): (int, int) = getMemCounters(allocator)
|
||||||
|
|
||||||
# -------------------- shared heap region ----------------------------------
|
# -------------------- shared heap region ----------------------------------
|
||||||
when hasThreadSupport:
|
|
||||||
var sharedHeap: MemRegion
|
|
||||||
var heapLock: SysLock
|
|
||||||
initSysLock(heapLock)
|
|
||||||
|
|
||||||
proc allocSharedImpl(size: Natural): pointer =
|
proc allocSharedImpl(size: Natural): pointer =
|
||||||
when hasThreadSupport:
|
when hasThreadSupport:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue