diff mbox

[FFmpeg-devel] Avoid creating unecessary dependencies on thread libraries.

Message ID 1479754359-7116-1-git-send-email-gregory.wolfe@kodakalaris.com
State Changes Requested
Headers show

Commit Message

Gregory J. Wolfe Nov. 21, 2016, 6:52 p.m. UTC
(1) 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.

(2) When ALL threading support is disabled, the build should not create a
dependency on ANY thread library.

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

Comments

Carl Eugen Hoyos Nov. 22, 2016, 1:11 a.m. UTC | #1
2016-11-21 19:52 GMT+01:00 Gregory J. Wolfe <gregory.wolfe@kodakalaris.com>:

> (2) When ALL threading support is disabled, the build should not create a
> dependency on ANY thread library.

If this done through "#if HAVE_THREADS", it would be preferable to
split the patches imo.

Carl Eugen
Gregory J. Wolfe Nov. 28, 2016, 4:29 p.m. UTC | #2
> -----Original Message-----

> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On

> Behalf Of Carl Eugen Hoyos

> Sent: Monday, November 21, 2016 8:12 PM

> To: FFmpeg development discussions and patches <ffmpeg-

> devel@ffmpeg.org>

> Subject: Re: [FFmpeg-devel] [PATCH] Avoid creating unecessary

> dependencies on thread libraries.

> 

> 2016-11-21 19:52 GMT+01:00 Gregory J. Wolfe

> <gregory.wolfe@kodakalaris.com>:

> 

> > (2) When ALL threading support is disabled, the build should not

> create a

> > dependency on ANY thread library.

> 

> If this done through "#if HAVE_THREADS", it would be preferable to

> split the patches imo.

> 

> Carl Eugen


Back from Thanksgiving holiday.  Will split patch into two and resubmit.

Greg W.
diff mbox

Patch

diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index f5785fc..a55921a 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -258,20 +258,25 @@  int av_cpu_count(void)
     static volatile int printed;
 
     int nb_cpus = 1;
+#if HAVE_THREADS
 #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);
@@ -286,6 +291,7 @@  int av_cpu_count(void)
     GetNativeSystemInfo(&sysinfo);
     nb_cpus = sysinfo.dwNumberOfProcessors;
 #endif
+#endif
 
     if (!printed) {
         av_log(NULL, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);