Ticket #52822: patch-gstreamer1-darwin-numcpufix-sysctl.diff

File patch-gstreamer1-darwin-numcpufix-sysctl.diff, 1.0 KB (added by ken-cunningham-webuse, 7 years ago)
  • plugins/tracers/gstrusage.c

    old new  
    3939#include <sys/resource.h>
    4040#endif
    4141
     42#include <sys/types.h>
     43#include <sys/sysctl.h>
     44
    4245GST_DEBUG_CATEGORY_STATIC (gst_rusage_debug);
    4346#define GST_CAT_DEFAULT gst_rusage_debug
    4447
     
    274277
    275278  gobject_class->finalize = gst_rusage_tracer_finalize;
    276279
    277   if ((num_cpus = sysconf (_SC_NPROCESSORS_ONLN)) == -1) {
    278     GST_WARNING ("failed to get number of cpus online");
    279     if ((num_cpus = sysconf (_SC_NPROCESSORS_CONF)) == -1) {
    280       GST_WARNING ("failed to get number of cpus, assuming 1");
    281       num_cpus = 1;
    282     }
     280  int nm[2];
     281  size_t len = 4;
     282  uint32_t count;
     283 
     284  nm[0] = CTL_HW; nm[1] = HW_AVAILCPU;
     285  sysctl(nm, 2, &count, &len, NULL, 0);
     286 
     287  if (count < 1) {
     288        nm[1] = HW_NCPU;
     289        sysctl(nm, 2, &count, &len, NULL, 0);
     290        if (count < 1) { count = 1; }
    283291  }
     292  num_cpus = (glong)count;
     293
    284294  GST_DEBUG ("rusage: num_cpus=%ld", num_cpus);
    285295
    286296  /* announce trace formats */