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

Unified Diff: src/platform-win32.cc

Issue 9662064: Remove static Mutex from math function intializers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 9 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
« src/platform-posix.cc ('K') | « src/platform-posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform-win32.cc
diff --git a/src/platform-win32.cc b/src/platform-win32.cc
index 2a25f044efa79beef6f9b8b72cbccfb41d8f461d..2776951c187cdda46be074429c5f683eaf6031e4 100644
--- a/src/platform-win32.cc
+++ b/src/platform-win32.cc
@@ -175,19 +175,17 @@ void OS::MemCopy(void* dest, const void* src, size_t size) {
#ifdef _WIN64
typedef double (*ModuloFunction)(double, double);
static ModuloFunction modulo_function = NULL;
-static LazyMutex modulo_function_mutex = LAZY_MUTEX_INITIALIZER;
+V8_DECLARE_ONCE(modulo_function_init_once);
// Defined in codegen-x64.cc.
ModuloFunction CreateModuloFunction();
+void init_modulo_function() {
+ modulo_function = CreateModuloFunction();
+ MemoryBarrier();
+}
+
double modulo(double x, double y) {
- if (modulo_function == NULL) {
- ScopedLock lock(modulo_function_mutex.Pointer());
- if (modulo_function == NULL) {
- ModuloFunction temp = CreateModuloFunction();
- MemoryBarrier();
- modulo_function = temp;
- }
- }
+ CallOnce(&modulo_function_init_once, &init_modulo_function);
// Note: here we rely on dependent reads being ordered. This is true
// on all architectures we currently support.
return (*modulo_function)(x, y);
@@ -208,17 +206,16 @@ double modulo(double x, double y) {
#endif // _WIN64
-static Mutex* math_function_mutex = OS::CreateMutex();
-
#define UNARY_MATH_FUNCTION(name, generator) \
static UnaryMathFunction fast_##name##_function = NULL; \
+V8_DECLARE_ONCE(fast_##name##_init_once); \
+void init_fast_##name##_function() { \
+ fast_##name##_function = generator; \
+ MemoryBarrier(); \
+} \
double fast_##name(double x) { \
- if (fast_##name##_function == NULL) { \
- ScopedLock lock(math_function_mutex); \
- UnaryMathFunction temp = generator; \
- MemoryBarrier(); \
- fast_##name##_function = temp; \
- } \
+ CallOnce(&fast_##name##_init_once, \
+ &init_fast_##name##_function); \
return (*fast_##name##_function)(x); \
}
« src/platform-posix.cc ('K') | « src/platform-posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698