Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(870)

Unified Diff: src/opts/opts_check_x86.cpp

Issue 655573002: Fix race in supports_simd(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: external linkage Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/opts/opts_check_x86.cpp
diff --git a/src/opts/opts_check_x86.cpp b/src/opts/opts_check_x86.cpp
index 55eb843312746b7e475eb776a6d35549e7553884..8fec2ba69c528040cbb02c2bd603bd1e00120a6f 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
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698