2019-10-13 00:01:15 +02:00
|
|
|
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2019-10-11 05:36:46 +02:00
|
|
|
module runtime
|
2019-10-11 23:54:25 +02:00
|
|
|
|
2019-10-13 00:01:15 +02:00
|
|
|
import os
|
|
|
|
|
|
|
|
//$if linux {
|
|
|
|
fn C.sysconf(name int) i64
|
|
|
|
//}
|
2019-10-11 23:54:25 +02:00
|
|
|
|
2019-10-13 00:01:15 +02:00
|
|
|
//$if windows {
|
|
|
|
fn C.GetCurrentProcessorNumber() u32
|
|
|
|
//}
|
2019-10-11 23:54:25 +02:00
|
|
|
|
|
|
|
pub fn nr_cpus() int {
|
2019-10-13 00:01:15 +02:00
|
|
|
$if linux {
|
|
|
|
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
|
|
|
|
}
|
|
|
|
$if mac {
|
|
|
|
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
|
|
|
|
}
|
|
|
|
$if windows {
|
|
|
|
mut nr := int(C.GetCurrentProcessorNumber())
|
|
|
|
if nr == 0 {
|
|
|
|
nr = os.getenv('NUMBER_OF_PROCESSORS').int()
|
|
|
|
}
|
|
|
|
return nr
|
|
|
|
}
|
|
|
|
return 1
|
2019-10-11 23:54:25 +02:00
|
|
|
}
|