[FFmpeg-devel] Avoid MinGW/Windows dependency on gcc thread library.

Submitted by Gregory J. Wolfe on Nov. 28, 2016, 8:14 p.m.

Details

Message ID 1480364083-4660-1-git-send-email-gregory.wolfe@kodakalaris.com
State New
Headers show

Commit Message

Gregory J. Wolfe Nov. 28, 2016, 8:14 p.m.
Multi-threading support requires knowing the number of CPUs available.
When building with MinGW on a Windows system, both Windows and gcc run
time functions are available to get this information.  If available,
the Windows function should be used, not the gcc function.  This avoids
creating an unnecessary dependency on the gcc thread library.

Signed-off-by: Gregory J. Wolfe <gregory.wolfe@kodakalaris.com>
---
 libavutil/cpu.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index 1803f6f..6ebc7ce 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -264,17 +264,21 @@  int av_cpu_count(void)
 #if HAVE_WINRT
     SYSTEM_INFO sysinfo;
 #endif
-#if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
+    // if HAVE_GETPROCESSAFFINITYMASK, we will use Windows
+    // GetProcessAffinityMask() over gcc library function
+    // sched_getaffinity().  This avoids creating a dependency
+    // on the gcc thread library that we don't need/want.
+#if HAVE_GETPROCESSAFFINITYMASK
+    DWORD_PTR proc_aff, sys_aff;
+    if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
+        nb_cpus = av_popcount64(proc_aff);
+#elif HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
     cpu_set_t cpuset;
 
     CPU_ZERO(&cpuset);
 
     if (!sched_getaffinity(0, sizeof(cpuset), &cpuset))
         nb_cpus = CPU_COUNT(&cpuset);
-#elif HAVE_GETPROCESSAFFINITYMASK
-    DWORD_PTR proc_aff, sys_aff;
-    if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
-        nb_cpus = av_popcount64(proc_aff);
 #elif HAVE_SYSCTL && defined(HW_NCPU)
     int mib[2] = { CTL_HW, HW_NCPU };
     size_t len = sizeof(nb_cpus);