shithub: mc

Download patch

ref: ec17d9295920ba33dee1fa5348bf35fca2b88665
parent: ba10ad8dba18db7dfcb934f67e23e405d7601ac5
author: Ori Bernstein <[email protected]>
date: Mon Sep 25 08:10:33 EDT 2017

Add ncpu for openbsd.

--- a/lib/thread/bld.sub
+++ b/lib/thread/bld.sub
@@ -41,8 +41,9 @@
 
 	# 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
--- /dev/null
+++ b/lib/thread/ncpu+openbsd.myr
@@ -1,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
+}