MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / init_cpu_count

Function init_cpu_count

libhb/ports.c:511–564  ·  view source on GitHub ↗

* Whenever possible, returns the number of CPUs on the current computer. * Returns 1 otherwise. */

Source from the content-addressed store, hash-verified

509 * Returns 1 otherwise.
510 */
511static int init_cpu_count()
512{
513 int cpu_count = 1;
514
515#if defined(SYS_CYGWIN) || defined(SYS_MINGW)
516 cpu_count = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
517
518#elif defined(SYS_LINUX)
519 unsigned int bit;
520 cpu_set_t p_aff;
521 memset( &p_aff, 0, sizeof(p_aff) );
522 sched_getaffinity( 0, sizeof(p_aff), &p_aff );
523 for( cpu_count = 0, bit = 0; bit < sizeof(p_aff); bit++ )
524 cpu_count += (((uint8_t *)&p_aff)[bit / 8] >> (bit % 8)) & 1;
525
526#elif defined(SYS_DARWIN) || defined(SYS_FREEBSD) || defined(SYS_NETBSD) || defined(SYS_OPENBSD)
527 size_t length = sizeof( cpu_count );
528#if defined SYS_OPENBSD || defined(SYS_NETBSD)
529#ifdef HW_NCPUONLINE
530 int mib[2] = { CTL_HW, HW_NCPUONLINE };
531#else
532 int mib[2] = { CTL_HW, HW_NCPU };
533#endif
534 if( sysctl(mib, 2, &cpu_count, &length, NULL, 0) )
535#else
536 if( sysctlbyname("hw.ncpu", &cpu_count, &length, NULL, 0) )
537#endif
538 {
539 cpu_count = 1;
540 }
541
542#elif defined( SYS_SunOS )
543 {
544 processorid_t cpumax;
545 int i,j=0;
546
547 cpumax = sysconf(_SC_CPUID_MAX);
548
549 for(i = 0; i <= cpumax; i++ )
550 {
551 if(p_online(i, P_STATUS) != -1)
552 {
553 j++;
554 }
555 }
556 cpu_count=j;
557 }
558#endif
559
560 cpu_count = MAX( 1, cpu_count );
561 cpu_count = MIN( cpu_count, 384 );
562
563 return cpu_count;
564}
565
566int hb_platform_init()
567{

Callers 1

init_cpu_infoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected