diff --git a/vlib/runtime/runtime.c.v b/vlib/runtime/runtime.c.v deleted file mode 100644 index 9b894087e3..0000000000 --- a/vlib/runtime/runtime.c.v +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2019-2021 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 { -fn C.sysconf(name int) i64 - -//} - -//$if windows { -fn C.GetCurrentProcessorNumber() u32 - -//} diff --git a/vlib/runtime/runtime.v b/vlib/runtime/runtime.v index 7079e8c2a2..4f92fe1a58 100644 --- a/vlib/runtime/runtime.v +++ b/vlib/runtime/runtime.v @@ -11,12 +11,15 @@ import os // then `nr_jobs` will return that number instead. // This is useful for runtime tweaking of e.g. threaded or concurrent code. pub fn nr_jobs() int { - mut cpus := nr_cpus() + mut cpus := nr_cpus() - 1 // allow for overrides, for example using `VJOBS=32 ./v test .` vjobs := os.getenv('VJOBS').int() if vjobs > 0 { cpus = vjobs } + if cpus == 0 { + return 1 + } return cpus } diff --git a/vlib/runtime/runtime_darwin.c.v b/vlib/runtime/runtime_darwin.c.v deleted file mode 100644 index 7777c00615..0000000000 --- a/vlib/runtime/runtime_darwin.c.v +++ /dev/null @@ -1 +0,0 @@ -module runtime diff --git a/vlib/runtime/runtime_linux.c.v b/vlib/runtime/runtime_linux.c.v deleted file mode 100644 index 7777c00615..0000000000 --- a/vlib/runtime/runtime_linux.c.v +++ /dev/null @@ -1 +0,0 @@ -module runtime diff --git a/vlib/runtime/runtime_nix.c.v b/vlib/runtime/runtime_nix.c.v index 2fe51d713d..a5c69b0544 100644 --- a/vlib/runtime/runtime_nix.c.v +++ b/vlib/runtime/runtime_nix.c.v @@ -1,14 +1,10 @@ module runtime +fn C.sysconf(name int) i64 + // nr_cpus returns the number of virtual CPU cores found on the system. pub fn nr_cpus() int { - $if linux { - return int(C.sysconf(C._SC_NPROCESSORS_ONLN)) - } - $if macos { - return int(C.sysconf(C._SC_NPROCESSORS_ONLN)) - } - $if solaris { + $if linux || macos || solaris { return int(C.sysconf(C._SC_NPROCESSORS_ONLN)) } return 1