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:
committed by
Alexander Medvednikov
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user