add comments to spawn and pinnedSpawn (#19230)

`spawn` uses `nimSpawn3` internally and `pinnedSpawn` uses `nimSpawn4` internally. I comment it in order to help contributors get the gist of its functionality.
This commit is contained in:
flywind 2021-12-10 01:49:31 +08:00 • committed by GitHub
commit 4f64c9fae5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -448,19 +448,21 @@ proc preferSpawn*(): bool =
## <#spawnX.t>`_ instead. ## <#spawnX.t>`_ instead.
result = gSomeReady.counter > 0 result = gSomeReady.counter > 0
proc spawn*(call: sink typed) {.magic: "Spawn".} proc spawn*(call: sink typed) {.magic: "Spawn".} =
## Always spawns a new task, so that the `call` is never executed on ## Always spawns a new task, so that the `call` is never executed on
## the calling thread. ## the calling thread.
## ##
## `call` has to be a proc call `p(...)` where `p` is gcsafe and has a ## `call` has to be a proc call `p(...)` where `p` is gcsafe and has a
## return type that is either `void` or compatible with `FlowVar[T]`. ## return type that is either `void` or compatible with `FlowVar[T]`.
discard "It uses `nimSpawn3` internally"
proc pinnedSpawn*(id: ThreadId; call: sink typed) {.magic: "Spawn".} proc pinnedSpawn*(id: ThreadId; call: sink typed) {.magic: "Spawn".} =
## Always spawns a new task on the worker thread with `id`, so that ## Always spawns a new task on the worker thread with `id`, so that
## the `call` is **always** executed on the thread. ## the `call` is **always** executed on the thread.
## ##
## `call` has to be a proc call `p(...)` where `p` is gcsafe and has a ## `call` has to be a proc call `p(...)` where `p` is gcsafe and has a
## return type that is either `void` or compatible with `FlowVar[T]`. ## return type that is either `void` or compatible with `FlowVar[T]`.
discard "It uses `nimSpawn4` internally"
template spawnX*(call) = template spawnX*(call) =
## Spawns a new task if a CPU core is ready, otherwise executes the ## Spawns a new task if a CPU core is ready, otherwise executes the