atomicInc global alloc counters (#20571)

This commit is contained in:
Antonis Geralis 2022-10-16 02:07:22 +03:00 • committed by GitHub
commit ed26156c99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View file

@ -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.}

View file

@ -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: