Merge pull request #46 from vibe-d/total_cpus

Use std.parallelism.totalCPUs to implement logicalProcessorCount.
This commit is contained in:
Sönke Ludwig 2018-02-14 13:09:02 +01:00 committed by GitHub
commit ff26c31a42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -602,35 +602,10 @@ public void setupWorkerThreads(uint num = logicalProcessorCount())
*/ */
public @property uint logicalProcessorCount() public @property uint logicalProcessorCount()
{ {
version (linux) { import std.parallelism : totalCPUs;
import core.sys.linux.sys.sysinfo; return totalCPUs;
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!");
} }
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 Suspends the execution of the calling task to let other tasks and events be