summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--lib/pure/concurrency/threadpool.nim2
-rw-r--r--lib/pure/nimprof.nim2
-rw-r--r--lib/pure/oids.nim3
-rw-r--r--lib/std/sysatomics.nim (renamed from lib/system/atomics.nim)10
-rw-r--r--lib/system.nim21
-rw-r--r--lib/system/alloc.nim1
7 files changed, 23 insertions, 17 deletions
diff --git a/changelog.md b/changelog.md
index ba52eff8a..80af02512 100644
--- a/changelog.md
+++ b/changelog.md
@@ -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.
diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim
index dcc917225..0eb20dc9a 100644
--- a/lib/pure/concurrency/threadpool.nim
+++ b/lib/pure/concurrency/threadpool.nim
@@ -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.}
 
diff --git a/lib/pure/nimprof.nim b/lib/pure/nimprof.nim
index fe497c645..7f493418e 100644
--- a/lib/pure/nimprof.nim
+++ b/lib/pure/nimprof.nim
@@ -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"
diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim
index 486e01ea3..e6e5e6e56 100644
--- a/lib/pure/oids.nim
+++ b/lib/pure/oids.nim
@@ -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
diff --git a/lib/system/atomics.nim b/lib/std/sysatomics.nim
index 61a60fa53..ddd8746c6 100644
--- a/lib/system/atomics.nim
+++ b/lib/std/sysatomics.nim
@@ -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)
diff --git a/lib/system.nim b/lib/system.nim
index ae07e58f3..c41b3cb9d 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -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.}
+
+  when not defined(nimPreviewSlimSystem):
+    import std/sysatomics
+    export sysatomics
+  else:
+    import std/sysatomics
 
-  proc atomicDec*(memLoc: var int, x: int = 1): int {.inline,
-                                                     discardable, raises: [], tags: [], benign.}
-  ## Atomic decrement of `memLoc`. Returns the value after the operation.
+  {.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
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index a99769725..69bab5a85 100644
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -12,6 +12,7 @@
 
 include osalloc
 import std/private/syslocks
+import std/sysatomics
 
 template track(op, address, size) =
   when defined(memTracker):