diff options
author | Ori Bernstein <ori@eigenstate.org> | 2016-11-20 19:00:23 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2016-11-20 19:00:23 -0800 |
commit | bb9114fe7f070794477f0cd0f907dcf709c3fd8b (patch) | |
tree | 5b980b45612263ac64236a4460403a73d46ffb0d /lib/thread | |
parent | 3e24000ddb275369ba68282e2c9406f6b1c23736 (diff) | |
download | mc-bb9114fe7f070794477f0cd0f907dcf709c3fd8b.tar.gz |
Allow requesting CPU counts on FreeBSD
Diffstat (limited to 'lib/thread')
-rw-r--r-- | lib/thread/ncpu+freebsd.myr | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/thread/ncpu+freebsd.myr b/lib/thread/ncpu+freebsd.myr new file mode 100644 index 0000000..1aa3dc1 --- /dev/null +++ b/lib/thread/ncpu+freebsd.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 +} |