From 9d503ae6a28314e6fe5242e492175396b3b6e7a6 Mon Sep 17 00:00:00 2001 From: Antonis Geralis Date: Sat, 15 Oct 2022 21:15:39 +0300 Subject: [PATCH] atomicInc global alloc counters --- lib/system.nim | 16 ++++++++-------- lib/system/memalloc.nim | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/system.nim b/lib/system.nim index bf528de104c04..c0e95a5d246a3 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1419,6 +1419,14 @@ when not defined(js) and not defined(booting) and defined(nimTrMacros): # unnecessary slow down in this case. swap(cast[ptr pointer](addr arr[a])[], cast[ptr pointer](addr arr[b])[]) +when not defined(nimscript): + proc atomicInc*(memLoc: var int, x: int = 1): int {.inline, + discardable, raises: [], tags: [], benign.} + ## Atomic increment of `memLoc`. Returns the value after the operation. + + proc atomicDec*(memLoc: var int, x: int = 1): int {.inline, + discardable, raises: [], tags: [], benign.} + ## Atomic decrement of `memLoc`. Returns the value after the operation. include "system/memalloc" @@ -1636,14 +1644,6 @@ when not declared(sysFatal): when not defined(nimscript): {.push stackTrace: off, profiler: off.} - proc atomicInc*(memLoc: var int, x: int = 1): int {.inline, - discardable, benign.} - ## Atomic increment of `memLoc`. Returns the value after the operation. - - proc atomicDec*(memLoc: var int, x: int = 1): int {.inline, - discardable, benign.} - ## Atomic decrement of `memLoc`. Returns the value after the operation. - include "system/atomics" {.pop.} diff --git a/lib/system/memalloc.nim b/lib/system/memalloc.nim index 7660bcd5827dc..a94d0995c89f9 100644 --- a/lib/system/memalloc.nim +++ b/lib/system/memalloc.nim @@ -80,7 +80,7 @@ when hasAlloc and not defined(js): when defined(nimAllocStats): var stats: AllocStats - template incStat(what: untyped) = inc stats.what + template incStat(what: untyped) = atomicInc stats.what proc getAllocStats*(): AllocStats = stats else: