move system/atomics out of system; std/atomics should be preferred (#20875)

* move `system/atomics` out of system; `std/atomics` should be preferred

* add deprecation message

* fixes

* fixes

* fixes

* fixes more tests
This commit is contained in:
ringabout 2022-11-23 03:39:30 +08:00 • committed by GitHub
commit 09b7f90475
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 17 deletions

View file

@ -16,6 +16,7 @@
- `std/objectdollar` - `std/objectdollar`
- `std/widestrs` - `std/widestrs`
- `std/typedthreads` - `std/typedthreads`
- `std/sysatomics`
In the future, these definitions will be removed from the `system` module, In the future, these definitions will be removed from the `system` module,
and their respective modules will have to be imported to use them. and their respective modules will have to be imported to use them.

View file

@ -23,7 +23,7 @@ when not compileOption("threads"):
import cpuinfo, cpuload, locks, os import cpuinfo, cpuload, locks, os
when defined(nimPreviewSlimSystem): when defined(nimPreviewSlimSystem):
import std/[assertions, typedthreads] import std/[assertions, typedthreads, sysatomics]
{.push stackTrace:off.} {.push stackTrace:off.}

View file

@ -24,7 +24,7 @@ when defined(nimHasUsed):
import hashes, algorithm, strutils, tables, sets import hashes, algorithm, strutils, tables, sets
when defined(nimPreviewSlimSystem): when defined(nimPreviewSlimSystem):
import std/syncio import std/[syncio, sysatomics]
when not defined(memProfiler): when not defined(memProfiler):
include "system/timers" include "system/timers"

View file

@ -17,6 +17,9 @@
import hashes, times, endians, random import hashes, times, endians, random
from std/private/decode_helpers import handleHexChar from std/private/decode_helpers import handleHexChar
when defined(nimPreviewSlimSystem):
import std/sysatomics
type type
Oid* = object ## An OID. Oid* = object ## An OID.
time: int64 time: int64

View file

@ -7,9 +7,14 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
when defined(nimPreviewSlimSystem):
{.deprecated: "use `std/atomics` instead".}
# Atomic operations for Nim. # Atomic operations for Nim.
{.push stackTrace:off, profiler:off.} {.push stackTrace:off, profiler:off.}
const
hasThreadSupport = compileOption("threads") and not defined(nimscript)
const someGcc = defined(gcc) or defined(llvm_gcc) or defined(clang) const someGcc = defined(gcc) or defined(llvm_gcc) or defined(clang)
const someVcc = defined(vcc) or defined(clang_cl) const someVcc = defined(vcc) or defined(clang_cl)
@ -215,7 +220,8 @@ else:
inc(p[], val) inc(p[], val)
result = p[] result = p[]
proc atomicInc*(memLoc: var int, x: int = 1): int =
proc atomicInc*(memLoc: var int, x: int = 1): int {.inline, discardable, raises: [], tags: [].} =
when someGcc and hasThreadSupport: when someGcc and hasThreadSupport:
result = atomicAddFetch(memLoc.addr, x, ATOMIC_SEQ_CST) result = atomicAddFetch(memLoc.addr, x, ATOMIC_SEQ_CST)
elif someVcc and hasThreadSupport: elif someVcc and hasThreadSupport:
@ -225,7 +231,7 @@ proc atomicInc*(memLoc: var int, x: int = 1): int =
inc(memLoc, x) inc(memLoc, x)
result = memLoc result = memLoc
proc atomicDec*(memLoc: var int, x: int = 1): int = proc atomicDec*(memLoc: var int, x: int = 1): int {.inline, discardable, raises: [], tags: [].} =
when someGcc and hasThreadSupport: when someGcc and hasThreadSupport:
when declared(atomicSubFetch): when declared(atomicSubFetch):
result = atomicSubFetch(memLoc.addr, x, ATOMIC_SEQ_CST) result = atomicSubFetch(memLoc.addr, x, ATOMIC_SEQ_CST)

View file

@ -1394,13 +1394,15 @@ when not defined(js) and not defined(booting) and defined(nimTrMacros):
swap(cast[ptr pointer](addr arr[a])[], cast[ptr pointer](addr arr[b])[]) swap(cast[ptr pointer](addr arr[a])[], cast[ptr pointer](addr arr[b])[])
when not defined(nimscript): when not defined(nimscript):
proc atomicInc*(memLoc: var int, x: int = 1): int {.inline, {.push stackTrace: off, profiler: off.}
discardable, raises: [], tags: [], benign.}
## Atomic increment of `memLoc`. Returns the value after the operation.
proc atomicDec*(memLoc: var int, x: int = 1): int {.inline, when not defined(nimPreviewSlimSystem):
discardable, raises: [], tags: [], benign.} import std/sysatomics
## Atomic decrement of `memLoc`. Returns the value after the operation. export sysatomics
else:
import std/sysatomics
{.pop.}
include "system/memalloc" include "system/memalloc"
@ -1617,13 +1619,6 @@ when not defined(nimscript):
when not declared(sysFatal): when not declared(sysFatal):
include "system/fatal" include "system/fatal"
when not defined(nimscript):
{.push stackTrace: off, profiler: off.}
include "system/atomics"
{.pop.}
when defined(nimV2): when defined(nimV2):
include system/arc include system/arc

View file

@ -12,6 +12,7 @@
include osalloc include osalloc
import std/private/syslocks import std/private/syslocks
import std/sysatomics
template track(op, address, size) = template track(op, address, size) =
when defined(memTracker): when defined(memTracker):