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
parent 8cfce70738
commit 09b7f90475
7 changed files with 23 additions and 17 deletions

View File

@@ -16,6 +16,7 @@
- `std/objectdollar`
- `std/widestrs`
- `std/typedthreads`
- `std/sysatomics`
In the future, these definitions will be removed from the `system` module,
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
when defined(nimPreviewSlimSystem):
import std/[assertions, typedthreads]
import std/[assertions, typedthreads, sysatomics]
{.push stackTrace:off.}

View File

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

View File

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

View File

@@ -7,9 +7,14 @@
# distribution, for details about the copyright.
#
when defined(nimPreviewSlimSystem):
{.deprecated: "use `std/atomics` instead".}
# Atomic operations for Nim.
{.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 someVcc = defined(vcc) or defined(clang_cl)
@@ -215,7 +220,8 @@ else:
inc(p[], val)
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:
result = atomicAddFetch(memLoc.addr, x, ATOMIC_SEQ_CST)
elif someVcc and hasThreadSupport:
@@ -225,7 +231,7 @@ proc atomicInc*(memLoc: var int, x: int = 1): int =
inc(memLoc, x)
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 declared(atomicSubFetch):
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])[])
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.
{.push stackTrace: off, profiler: off.}
proc atomicDec*(memLoc: var int, x: int = 1): int {.inline,
discardable, raises: [], tags: [], benign.}
## Atomic decrement of `memLoc`. Returns the value after the operation.
when not defined(nimPreviewSlimSystem):
import std/sysatomics
export sysatomics
else:
import std/sysatomics
{.pop.}
include "system/memalloc"
@@ -1617,13 +1619,6 @@ when not defined(nimscript):
when not declared(sysFatal):
include "system/fatal"
when not defined(nimscript):
{.push stackTrace: off, profiler: off.}
include "system/atomics"
{.pop.}
when defined(nimV2):
include system/arc

View File

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