From 1ed1c85f76cbc7c2170fdf7b487fe6b029bfcddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 20 Dec 2017 11:02:15 +0100 Subject: [PATCH] Use std.parallelism.totalCPUs to implement logicalProcessorCount. See vibe-d/vibe.d#2008. --- source/vibe/core/core.d | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/source/vibe/core/core.d b/source/vibe/core/core.d index 3c755c6..83bef51 100644 --- a/source/vibe/core/core.d +++ b/source/vibe/core/core.d @@ -602,35 +602,10 @@ public void setupWorkerThreads(uint num = logicalProcessorCount()) */ public @property uint logicalProcessorCount() { - version (linux) { - import core.sys.linux.sys.sysinfo; - return get_nprocs(); - } else version (OSX) { - int count; - size_t count_len = count.sizeof; - sysctlbyname("hw.logicalcpu", &count, &count_len, null, 0); - return cast(uint)count_len; - } else version (FreeBSD) { - int count; - size_t count_len = count.sizeof; - sysctlbyname("hw.logicalcpu", &count, &count_len, null, 0); - return cast(uint)count_len; - } else version (NetBSD) { - int count; - size_t count_len = count.sizeof; - sysctlbyname("hw.logicalcpu", &count, &count_len, null, 0); - return cast(uint)count_len; - } else version (Windows) { - import core.sys.windows.windows; - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; - } else static assert(false, "Unsupported OS!"); + import std.parallelism : totalCPUs; + return totalCPUs; } -version (OSX) private extern(C) int sysctlbyname(const(char)* name, void* oldp, size_t* oldlen, void* newp, size_t newlen); -version (FreeBSD) private extern(C) int sysctlbyname(const(char)* name, void* oldp, size_t* oldlen, void* newp, size_t newlen); -version (NetBSD) private extern(C) int sysctlbyname(const(char)* name, void* oldp, size_t* oldlen, void* newp, size_t newlen); -version (linux) static if (__VERSION__ <= 2066) private extern(C) int get_nprocs(); + /** Suspends the execution of the calling task to let other tasks and events be