summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/system.nim14
-rw-r--r--lib/system/alloc.nim16
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/system.nim b/lib/system.nim
index ad98540a7..c69a335e4 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1434,6 +1434,20 @@ when not defined(nimrodVM) and hostOS != "standalone":
   proc getTotalMem*(): int {.rtl.}
     ## returns the number of bytes that are owned by the process.
 
+  when hasThreadSupport:
+    proc getOccupiedSharedMem*(): int {.rtl.}
+      ## returns the number of bytes that are owned by the process
+      ## on the shared heap and hold data. This is only available when
+      ## threads are enabled.
+
+    proc getFreeSharedMem*(): int {.rtl.}
+      ## returns the number of bytes that are owned by the
+      ## process on the shared heap, but do not hold any meaningful data.
+      ## This is only available when threads are enabled.
+
+    proc getTotalSharedMem*(): int {.rtl.}
+      ## returns the number of bytes on the shared heap that are owned by the
+      ## process. This is only available when threads are enabled.
 
 iterator countdown*[T](a, b: T, step = 1): T {.inline.} =
   ## Counts from ordinal value `a` down to `b` with the given
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index eaef6cd95..602e5c7fa 100644
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -835,4 +835,20 @@ template instantiateForRegion(allocator: expr) =
     else:
       result = realloc(p, newsize)
 
+  when hasThreadSupport:
+
+    template sharedMemStatsShared(v: int) {.immediate.} =
+      acquireSys(heapLock)
+      result = v
+      releaseSys(heapLock)
+
+    proc getFreeSharedMem(): int =
+      sharedMemStatsShared(sharedHeap.freeMem)
+
+    proc getTotalSharedMem(): int =
+      sharedMemStatsShared(sharedHeap.currMem)
+
+    proc getOccupiedSharedMem(): int =
+      sharedMemStatsShared(sharedHeap.currMem - sharedHeap.freeMem)
+
 {.pop.}