Commit 2d608a5f authored by Henrik Gramner's avatar Henrik Gramner Committed by Henrik Gramner

Fix potential race condition in dav1d_get_cpu_flags()

parent 7b208fa8
......@@ -30,24 +30,22 @@
#include "src/cpu.h"
static unsigned flags = 0;
static unsigned flags_mask = -1;
COLD unsigned dav1d_get_cpu_flags(void) {
static unsigned flags;
static uint8_t checked = 0;
if (!checked) {
#if (ARCH_AARCH64 || ARCH_ARM) && HAVE_ASM
flags = dav1d_get_cpu_flags_arm();
#elif ARCH_PPC64LE && HAVE_ASM
flags = dav1d_get_cpu_flags_ppc();
#elif ARCH_X86 && HAVE_ASM
flags = dav1d_get_cpu_flags_x86();
#else
flags = 0;
COLD void dav1d_init_cpu(void) {
#if HAVE_ASM
#if ARCH_AARCH64 || ARCH_ARM
flags = dav1d_get_cpu_flags_arm();
#elif ARCH_PPC64LE
flags = dav1d_get_cpu_flags_ppc();
#elif ARCH_X86
flags = dav1d_get_cpu_flags_x86();
#endif
#endif
checked = 1;
}
}
COLD unsigned dav1d_get_cpu_flags(void) {
return flags & flags_mask;
}
......
......@@ -42,7 +42,8 @@
#include "src/x86/cpu.h"
#endif
void dav1d_init_cpu(void);
unsigned dav1d_get_cpu_flags(void);
DAV1D_API void dav1d_set_cpu_flags_mask(const unsigned mask);
DAV1D_API void dav1d_set_cpu_flags_mask(unsigned mask);
#endif /* DAV1D_SRC_CPU_H */
......@@ -37,6 +37,7 @@
#include "common/mem.h"
#include "common/validate.h"
#include "src/cpu.h"
#include "src/fg_apply.h"
#include "src/internal.h"
#include "src/log.h"
......@@ -47,10 +48,11 @@
#include "src/wedge.h"
static COLD void init_internal(void) {
dav1d_init_wedge_masks();
dav1d_init_cpu();
dav1d_init_interintra_masks();
dav1d_init_qm_tables();
dav1d_init_thread();
dav1d_init_wedge_masks();
}
COLD const char *dav1d_version(void) {
......
......@@ -569,6 +569,7 @@ int main(int argc, char *argv[]) {
if (state.function_listing) {
print_functions(state.funcs);
} else {
dav1d_init_cpu();
for (int i = 0; cpus[i].flag; i++)
check_cpu_flag(cpus[i].name, cpus[i].flag);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment