diff options
author | Marek Olšák <[email protected]> | 2018-09-05 19:15:56 -0400 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2018-09-07 15:48:31 -0400 |
commit | a84fd58f48fa332b1c5a545d9b7e2440b8784656 (patch) | |
tree | ab7ef432dda6863482103422feaec7b0752a15c8 /src/gallium | |
parent | 8396043f304bb2a752130230055605c5c966e89f (diff) |
gallium/u_cpu_detect: fix a race condition on initialization
Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/auxiliary/util/u_cpu_detect.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/gallium/auxiliary/util/u_cpu_detect.c b/src/gallium/auxiliary/util/u_cpu_detect.c index 14003aa7692..93cf58011db 100644 --- a/src/gallium/auxiliary/util/u_cpu_detect.c +++ b/src/gallium/auxiliary/util/u_cpu_detect.c @@ -36,6 +36,7 @@ #include "u_debug.h" #include "u_cpu_detect.h" +#include "c11/threads.h" #if defined(PIPE_ARCH_PPC) #if defined(PIPE_OS_APPLE) @@ -366,14 +367,9 @@ check_os_arm_support(void) } #endif /* PIPE_ARCH_ARM */ -void -util_cpu_detect(void) +static void +util_cpu_detect_once(void) { - static boolean util_cpu_detect_initialized = FALSE; - - if(util_cpu_detect_initialized) - return; - memset(&util_cpu_caps, 0, sizeof util_cpu_caps); /* Count the number of CPUs in system */ @@ -561,6 +557,12 @@ util_cpu_detect(void) debug_printf("util_cpu_caps.has_avx512vbmi = %u\n", util_cpu_caps.has_avx512vbmi); } #endif +} + +static once_flag cpu_once_flag = ONCE_FLAG_INIT; - util_cpu_detect_initialized = TRUE; +void +util_cpu_detect(void) +{ + call_once(&cpu_once_flag, util_cpu_detect_once); } |