aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-10-13 12:48:16 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-13 12:48:16 -0700
commitc09e2af17fab03d3d36c20e5201a560c3e4c233e (patch)
treeb7f5e070f4e2f7fc4fc38132110a38a6efe93530 /src
parent0880686d9586e719fed5eb157919c3cdb1f0a450 (diff)
Fix race in supports_simd().
Local statics are not thread safe in Chrome. Use an SkLazyPtr instead. See https://code.google.com/p/chromium/issues/detail?id=418041 BUG=418041 Review URL: https://codereview.chromium.org/655573002
Diffstat (limited to 'src')
-rw-r--r--src/opts/opts_check_x86.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/opts/opts_check_x86.cpp b/src/opts/opts_check_x86.cpp
index 55eb843312..8fec2ba69c 100644
--- a/src/opts/opts_check_x86.cpp
+++ b/src/opts/opts_check_x86.cpp
@@ -16,6 +16,7 @@
#include "SkBlitRow_opts_SSE4.h"
#include "SkBlurImage_opts_SSE2.h"
#include "SkBlurImage_opts_SSE4.h"
+#include "SkLazyPtr.h"
#include "SkMorphology_opts.h"
#include "SkMorphology_opts_SSE2.h"
#include "SkRTConf.h"
@@ -79,22 +80,29 @@ static inline void getcpuid(int info_type, int info[4]) {
/* Fetch the SIMD level directly from the CPU, at run-time.
* Only checks the levels needed by the optimizations in this file.
*/
-static int get_SIMD_level() {
- int cpu_info[4] = { 0 };
-
+namespace { // get_SIMD_level() technically must have external linkage, so no static.
+int* get_SIMD_level() {
+ int cpu_info[4] = { 0, 0, 0, 0 };
getcpuid(1, cpu_info);
+
+ int* level = SkNEW(int);
+
if ((cpu_info[2] & (1<<20)) != 0) {
- return SK_CPU_SSE_LEVEL_SSE42;
+ *level = SK_CPU_SSE_LEVEL_SSE42;
} else if ((cpu_info[2] & (1<<19)) != 0) {
- return SK_CPU_SSE_LEVEL_SSE41;
+ *level = SK_CPU_SSE_LEVEL_SSE41;
} else if ((cpu_info[2] & (1<<9)) != 0) {
- return SK_CPU_SSE_LEVEL_SSSE3;
+ *level = SK_CPU_SSE_LEVEL_SSSE3;
} else if ((cpu_info[3] & (1<<26)) != 0) {
- return SK_CPU_SSE_LEVEL_SSE2;
+ *level = SK_CPU_SSE_LEVEL_SSE2;
} else {
- return 0;
+ *level = 0;
}
+ return level;
}
+} // namespace
+
+SK_DECLARE_STATIC_LAZY_PTR(int, gSIMDLevel, get_SIMD_level);
/* Verify that the requested SIMD level is supported in the build.
* If not, check if the platform supports it.
@@ -115,8 +123,7 @@ static inline bool supports_simd(int minLevel) {
*/
return false;
#else
- static int gSIMDLevel = get_SIMD_level();
- return (minLevel <= gSIMDLevel);
+ return minLevel <= *gSIMDLevel.get();
#endif
}
}