put std/threads under the umbrella of nimPreviewSlimSystem (#20711)

* put `std/threads` under the umbrella of `nimPreviewSlimSystem`

* add changelog

* fixes tests

* fixes tests again

* fixes tests
This commit is contained in:
ringabout
2022-10-31 13:36:50 +08:00
committed by GitHub
parent fb2ec8d192
commit e1ddd2d524
13 changed files with 33 additions and 19 deletions

View File

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

View File

@@ -76,7 +76,7 @@ import algorithm, math
import std/private/since
when defined(nimPreviewSlimSystem):
import std/assertions
import std/[assertions]
include system/inclrtl
{.push debugger: off.}

View File

@@ -95,16 +95,6 @@ when defined(zephyr):
proc onThreadDestruction*(handler: proc () {.closure, gcsafe, raises: [].}) =
## Registers a *thread local* handler that is called at the thread's
## destruction.
##
## A thread is destructed when the `.thread` proc returns
## normally or when it raises an exception. Note that unhandled exceptions
## in a thread nevertheless cause the whole process to die.
nimThreadDestructionHandlers.add handler
{.push stack_trace:off.}
when defined(windows):
proc threadProcWrapper[TArg](closure: pointer): int32 {.stdcall.} =

View File

@@ -2093,9 +2093,10 @@ when not defined(js):
when hasThreadSupport:
when hostOS != "standalone":
include system/threadimpl
import std/threads
export threads
when not defined(nimPreviewSlimSystem):
{.deprecated: "threads is about to move out of system; use `-d:nimPreviewSlimSystem` and import `std/threads`".}
import std/threads
export threads
elif not defined(nogc) and not defined(nimscript):
when not defined(useNimRtl) and not defined(createNimRtl): initStackBottom()

View File

@@ -33,6 +33,15 @@ template afterThreadRuns() =
for i in countdown(nimThreadDestructionHandlers.len-1, 0):
nimThreadDestructionHandlers[i]()
proc onThreadDestruction*(handler: proc () {.closure, gcsafe, raises: [].}) =
## Registers a *thread local* handler that is called at the thread's
## destruction.
##
## A thread is destructed when the `.thread` proc returns
## normally or when it raises an exception. Note that unhandled exceptions
## in a thread nevertheless cause the whole process to die.
nimThreadDestructionHandlers.add handler
when defined(boehmgc):
type GCStackBaseProc = proc(sb: pointer, t: pointer) {.noconv.}
proc boehmGC_call_with_stack_base(sbp: GCStackBaseProc, p: pointer)