runtime: nr_cpus()

pull/2293/head
Alexander Medvednikov 2019-10-11 06:36:46 +03:00
parent a280e98d7f
commit 52c2fa44b8
6 changed files with 24 additions and 5 deletions

View File

@ -1686,7 +1686,7 @@ fn (p mut Parser) bterm() string {
// also called on *, &, @, . (enum) // also called on *, &, @, . (enum)
fn (p mut Parser) name_expr() string { fn (p mut Parser) name_expr() string {
//println('n') //println('n')
p.has_immutable_field = false p.has_immutable_field = false
p.is_const_literal = false p.is_const_literal = false
ph := p.cgen.add_placeholder() ph := p.cgen.add_placeholder()

View File

@ -31,7 +31,6 @@ struct VargAccess {
index int index int
} }
/*
enum NameCategory { enum NameCategory {
constant constant
mod mod
@ -41,8 +40,8 @@ enum NameCategory {
struct Name { struct Name {
cat NameCategory cat NameCategory
idx int // e.g. typ := types[name.idx]
} }
*/
struct GenTable { struct GenTable {
fn_name string fn_name string

View File

@ -35,7 +35,7 @@ const (
) )
fn new_hashmap(planned_nr_items int) hashmap { fn new_hashmap(planned_nr_items int) hashmap {
mut cap := planned_nr_items * 3 mut cap := planned_nr_items * 5
if cap < min_cap { if cap < min_cap {
cap = min_cap cap = min_cap
} }

View File

@ -177,7 +177,7 @@ pub fn (m &map) keys() []string {
} }
fn (m map) get(key string, out voidptr) bool { fn (m map) get(key string, out voidptr) bool {
//println('g') println('g')
if m.root == 0 { if m.root == 0 {
return false return false
} }

View File

@ -0,0 +1,13 @@
// 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
#include <sys/sysinfo.h>
fn C.get_nprocs() int
pub fn nr_cpus() int {
return C.get_nprocs()
}

View File

@ -0,0 +1,7 @@
import runtime
fn test_nr_cpus() {
nr_cpus := runtime.nr_cpus()
println(nr_cpus)
assert nr_cpus > 0
}