Message ID | 1618226529-22995-1-git-send-email-kevin.j.wheatley@gmail.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel] libavutil/cpu: Fix definition of _GNU_SOURCE so it occurs before other includes | expand |
Context | Check | Description |
---|---|---|
andriy/x86_make | success | Make finished |
andriy/x86_make_fate | success | Make fate finished |
andriy/PPC64_make | success | Make finished |
andriy/PPC64_make_fate | success | Make fate finished |
On Mon, Apr 12, 2021 at 12:22 PM <kevin.j.wheatley@gmail.com> wrote: > > From: Kevin Wheatley <kevin.j.wheatley@gmail.com> > > This fix moves the potential definition of _GNU_SOURCE prior to > any includes of system header files as required by the documentation > https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html > > This corrects the CPU_COUNT macro availability, resulting in > sched_getaffinity() being called on Linux systems. This then correctly > returns the number of CPUs when run under containers and other cases > where processor affinity has been setup prior to running FFmpeg > bump As an FYI the issue is triggered because the inclusion of the other system headers prior to the _GNU_SOURCE definition results in the CPU_COUNT macro not being defined, and so the affinity based CPU counting fails to be used and so the cpu count is incorrectly returned. Kevin
diff --git a/libavutil/cpu.c b/libavutil/cpu.c index 8e3576a..1496c5d 100644 --- a/libavutil/cpu.c +++ b/libavutil/cpu.c @@ -16,6 +16,15 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" + +#if HAVE_SCHED_GETAFFINITY +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif +#include <sched.h> +#endif + #include <stddef.h> #include <stdint.h> #include <stdatomic.h> @@ -23,16 +32,9 @@ #include "attributes.h" #include "cpu.h" #include "cpu_internal.h" -#include "config.h" #include "opt.h" #include "common.h" -#if HAVE_SCHED_GETAFFINITY -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif -#include <sched.h> -#endif #if HAVE_GETPROCESSAFFINITYMASK || HAVE_WINRT #include <windows.h> #endif