Skip to content

Commit

Permalink
Minor docs/format changes (cpuinfo, volatile) (nim-lang#16602)
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumlamm authored and mildred committed Jan 11, 2021
1 parent 358716b commit f919f37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions lib/pure/concurrency/cpuinfo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@
# distribution, for details about the copyright.
#

## This module implements procs to determine the number of CPUs / cores.
## This module implements a proc to determine the number of CPUs / cores.

runnableExamples:
doAssert countProcessors() > 0


include "system/inclrtl"

when not defined(windows):
import posix

when defined(freebsd) or defined(macosx):
{.emit:"#include <sys/types.h>".}
{.emit: "#include <sys/types.h>".}

when defined(openbsd) or defined(netbsd):
{.emit:"#include <sys/param.h>".}
{.emit: "#include <sys/param.h>".}

when defined(macosx) or defined(bsd):
# we HAVE to emit param.h before sysctl.h so we cannot use .header here
# either. The amount of archaic bullshit in Poonix based OSes is just insane.
{.emit:"#include <sys/sysctl.h>".}
{.emit: "#include <sys/sysctl.h>".}
const
CTL_HW = 6
HW_AVAILCPU = 25
Expand All @@ -47,7 +51,7 @@ when defined(haiku):
header: "<OS.h>".}

proc countProcessors*(): int {.rtl, extern: "ncpi$1".} =
## returns the number of the processors/cores the machine has.
## Returns the number of the processors/cores the machine has.
## Returns 0 if it cannot be detected.
when defined(windows):
type
Expand Down Expand Up @@ -95,8 +99,3 @@ proc countProcessors*(): int {.rtl, extern: "ncpi$1".} =
else:
result = sysconf(SC_NPROCESSORS_ONLN)
if result <= 0: result = 0


runnableExamples:
block:
doAssert countProcessors() > 0
4 changes: 2 additions & 2 deletions lib/pure/volatile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

template volatileLoad*[T](src: ptr T): T =
## Generates a volatile load of the value stored in the container `src`.
## Note that this only effects code generation on `C` like backends
## Note that this only effects code generation on `C` like backends.
when nimvm:
src[]
else:
Expand All @@ -26,7 +26,7 @@ template volatileLoad*[T](src: ptr T): T =
template volatileStore*[T](dest: ptr T, val: T) =
## Generates a volatile store into the container `dest` of the value
## `val`. Note that this only effects code generation on `C` like
## backends
## backends.
when nimvm:
dest[] = val
else:
Expand Down

0 comments on commit f919f37

Please sign in to comment.