summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-09-25 12:10:33 -0700
committerOri Bernstein <ori@eigenstate.org>2017-10-12 11:53:18 -0700
commitec17d9295920ba33dee1fa5348bf35fca2b88665 (patch)
treec800341ddee2de8a81e658372369f0b693a69d6d
parentba10ad8dba18db7dfcb934f67e23e405d7601ac5 (diff)
downloadmc-ec17d9295920ba33dee1fa5348bf35fca2b88665.tar.gz
Add ncpu for openbsd.
-rw-r--r--lib/thread/bld.sub3
-rw-r--r--lib/thread/ncpu+openbsd.myr23
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/thread/bld.sub b/lib/thread/bld.sub
index 4318db3..f386162 100644
--- a/lib/thread/bld.sub
+++ b/lib/thread/bld.sub
@@ -41,8 +41,9 @@ lib thread =
# openbsd impl of thread primitives
exit+openbsd-x64.s
- spawn+openbsd.myr
mutex+openbsd:6.2.myr
+ ncpu+openbsd.myr
+ spawn+openbsd.myr
atomic-impl+x64.s
atomic.myr
diff --git a/lib/thread/ncpu+openbsd.myr b/lib/thread/ncpu+openbsd.myr
new file mode 100644
index 0000000..1aa3dc1
--- /dev/null
+++ b/lib/thread/ncpu+openbsd.myr
@@ -0,0 +1,23 @@
+use std
+use sys
+
+pkg thread =
+ const ncpu : (-> int)
+;;
+
+const ncpu = {
+ var mib : int[2]
+ var ncpu : int
+ var ncpusz
+ var res
+
+ mib[0] = 6 /* CTL_HW */
+ mib[1] = 3 /* HW_NCPU */
+ ncpusz = sizeof(int)
+
+ res = sys.sysctl(mib[:], (&ncpu : void#), &ncpusz, (0 : void#), (0 : sys.size#))
+ if res < 0 || ncpu <= 0
+ -> 1
+ ;;
+ -> ncpu
+}