Use std.parallelism.totalCPUs to implement logicalProcessorCount.
See vibe-d/vibe.d#2008.
This commit is contained in:
parent
c9aaf0cb29
commit
1ed1c85f76
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue