mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
runtime: add windows support for nr_cpus()
This commit is contained in:
parent
432e074b4e
commit
1292163637
@ -1,16 +1,32 @@
|
||||
// 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.
|
||||
|
||||
module runtime
|
||||
|
||||
/*
|
||||
$if linux {
|
||||
#include <sys/sysinfo.h>
|
||||
fn C.get_nprocs() int
|
||||
}
|
||||
*/
|
||||
import os
|
||||
|
||||
//$if linux {
|
||||
fn C.sysconf(name int) i64
|
||||
//}
|
||||
|
||||
//$if windows {
|
||||
fn C.GetCurrentProcessorNumber() u32
|
||||
//}
|
||||
|
||||
pub fn nr_cpus() int {
|
||||
//$if linux {
|
||||
//return C.get_nprocs()
|
||||
//}
|
||||
return 0
|
||||
$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
|
||||
}
|
||||
|
@ -1,6 +1 @@
|
||||
// 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.
|
||||
|
||||
module runtime
|
||||
|
||||
|
@ -1,2 +1 @@
|
||||
module runtime
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
import runtime
|
||||
|
||||
fn test_nr_cpus() {
|
||||
$if linux {
|
||||
nr_cpus := runtime.nr_cpus()
|
||||
println(nr_cpus)
|
||||
assert nr_cpus >= 0
|
||||
}
|
||||
}
|
||||
nr_cpus := runtime.nr_cpus()
|
||||
assert nr_cpus > 0
|
||||
}
|
||||
|
@ -1,2 +1 @@
|
||||
module runtime
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user