[x264-devel] [PATCH] Make use of _SC_NPROCESSORS_ONLN on OpenBSD

Brad Smith brad at comstyle.com
Sat Apr 3 20:53:21 UTC 2021


Make use of _SC_NPROCESSORS_ONLN on OpenBSD.

Modern versions of OpenBSD the online number vs configured
can be different.

diff --git a/common/cpu.c b/common/cpu.c
index 96585aa8..46e9b514 100644
--- a/common/cpu.c
+++ b/common/cpu.c
@@ -433,7 +433,7 @@ int x264_cpu_num_processors( void )
 #elif SYS_WINDOWS
     return x264_pthread_num_processors_np();
 
-#elif SYS_CYGWIN || SYS_SunOS
+#elif SYS_CYGWIN || SYS_SunOS || SYS_OPENBSD
     return sysconf( _SC_NPROCESSORS_ONLN );
 
 #elif SYS_LINUX
@@ -460,15 +460,10 @@ int x264_cpu_num_processors( void )
     get_system_info( &info );
     return info.cpu_count;
 
-#elif SYS_MACOSX || SYS_FREEBSD || SYS_OPENBSD
+#elif SYS_MACOSX || SYS_FREEBSD
     int ncpu;
     size_t length = sizeof( ncpu );
-#if SYS_OPENBSD
-    int mib[2] = { CTL_HW, HW_NCPU };
-    if( sysctl(mib, 2, &ncpu, &length, NULL, 0) )
-#else
     if( sysctlbyname("hw.ncpu", &ncpu, &length, NULL, 0) )
-#endif
     {
         ncpu = 1;
     }


More information about the x264-devel mailing list