From b47d12fe0ab2cdd7f86d3be50f03c474a98ceb7d Mon Sep 17 00:00:00 2001 From: Antonis Geralis <43617260+planetis-m@users.noreply.github.com> Date: Sun, 16 Oct 2022 02:07:22 +0300 Subject: [PATCH] atomicInc global alloc counters (#20571) (cherry picked from commit ed26156c99d1bbcfc10ae77f8f50628a561734ff) --- 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 c8dcdbf133..98855adc8b 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1536,6 +1536,14 @@ const ## and expect a reasonable result - use the `isNaN` or `classify` procedure ## in the `math module `_ for checking for NaN. +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" @@ -1808,14 +1816,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 49766e69db..879a1f0661 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: