2019-10-13 01:01:15 +03: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 06:36:46 +03:00
|
|
|
module runtime
|
2019-10-12 00:54:25 +03:00
|
|
|
|
2019-10-13 01:01:15 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
//$if linux {
|
|
|
|
fn C.sysconf(name int) i64
|
|
|
|
//}
|
2019-10-12 00:54:25 +03:00
|
|
|
|
2019-10-13 01:01:15 +03:00
|
|
|
//$if windows {
|
|
|
|
fn C.GetCurrentProcessorNumber() u32
|
|
|
|
//}
|
2019-10-12 00:54:25 +03:00
|
|
|
|
|
|
|
pub fn nr_cpus() int {
|
2019-10-13 01:01:15 +03: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-12 00:54:25 +03:00
|
|
|
}
|