Imported Upstream version 1.34.0
[platform/upstream/grpc.git] / src / core / lib / gpr / cpu_iphone.cc
index 2847e03..94a724d 100644 (file)
 
 #ifdef GPR_CPU_IPHONE
 
-/* Probably 2 instead of 1, but see comment on gpr_cpu_current_cpu. */
-unsigned gpr_cpu_num_cores(void) { return 1; }
+#include <sys/sysctl.h>
+
+unsigned gpr_cpu_num_cores(void) {
+  size_t len;
+  unsigned int ncpu;
+  len = sizeof(ncpu);
+  sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);
+
+  return ncpu;
+}
 
 /* Most code that's using this is using it to shard across work queues. So
    unless profiling shows it's a problem or there appears a way to detect the