avutil/cpu: remove the |checked| static variable

Remove the |checked| variable because the invalid value of -1 for
|flags| can be used to indicate the same condition. Also rename |flags|
to |cpu_flags| because there are a local variable and a function
parameter named |flags| in the same file.

Co-author: Dmitry Vyukov of Google

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Wan-Teh Chang 2016-11-23 11:21:56 -08:00 committed by Michael Niedermayer
parent dd10e7253a
commit 29fb49194b
1 changed files with 21 additions and 19 deletions

View File

@ -44,7 +44,20 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
static int flags, checked; static int cpu_flags = -1;
static int get_cpu_flags(void)
{
if (ARCH_AARCH64)
return ff_get_cpu_flags_aarch64();
if (ARCH_ARM)
return ff_get_cpu_flags_arm();
if (ARCH_PPC)
return ff_get_cpu_flags_ppc();
if (ARCH_X86)
return ff_get_cpu_flags_x86();
return 0;
}
void av_force_cpu_flags(int arg){ void av_force_cpu_flags(int arg){
if ( (arg & ( AV_CPU_FLAG_3DNOW | if ( (arg & ( AV_CPU_FLAG_3DNOW |
@ -69,33 +82,22 @@ void av_force_cpu_flags(int arg){
arg |= AV_CPU_FLAG_MMX; arg |= AV_CPU_FLAG_MMX;
} }
flags = arg; cpu_flags = arg;
checked = arg != -1;
} }
int av_get_cpu_flags(void) int av_get_cpu_flags(void)
{ {
if (checked) int flags = cpu_flags;
return flags; if (flags == -1) {
flags = get_cpu_flags();
if (ARCH_AARCH64) cpu_flags = flags;
flags = ff_get_cpu_flags_aarch64(); }
if (ARCH_ARM)
flags = ff_get_cpu_flags_arm();
if (ARCH_PPC)
flags = ff_get_cpu_flags_ppc();
if (ARCH_X86)
flags = ff_get_cpu_flags_x86();
checked = 1;
return flags; return flags;
} }
void av_set_cpu_flags_mask(int mask) void av_set_cpu_flags_mask(int mask)
{ {
checked = 0; cpu_flags = get_cpu_flags() & mask;
flags = av_get_cpu_flags() & mask;
checked = 1;
} }
int av_parse_cpu_flags(const char *s) int av_parse_cpu_flags(const char *s)