Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atomicInc global alloc counters #20571

Merged
merged 1 commit into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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.}
Expand Down
2 changes: 1 addition & 1 deletion lib/system/memalloc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down