Revision: 11015
Author:   [email protected]
Date:     Mon Mar 12 10:15:13 2012
Log:      Remove static Mutex from math function intializers.

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com/9662064
http://code.google.com/p/v8/source/detail?r=11015

Modified:
 /branches/bleeding_edge/src/platform-posix.cc
 /branches/bleeding_edge/src/platform-win32.cc

=======================================
--- /branches/bleeding_edge/src/platform-posix.cc       Mon Mar 12 09:10:53 2012
+++ /branches/bleeding_edge/src/platform-posix.cc       Mon Mar 12 10:15:13 2012
@@ -127,17 +127,15 @@
 }


-static LazyMutex math_function_mutex = LAZY_MUTEX_INITIALIZER;
-
 #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;                    \
+}                                                        \
 double fast_##name(double x) {                           \
-  if (fast_##name##_function == NULL) {                  \
-    ScopedLock lock(math_function_mutex.Pointer());      \
-    UnaryMathFunction temp = generator;                  \
-    MemoryBarrier();                                     \
-    fast_##name##_function = temp;                       \
-  }                                                      \
+  CallOnce(&fast_##name##_init_once,                     \
+           &init_fast_##name##_function);                \
   return (*fast_##name##_function)(x);                   \
 }

=======================================
--- /branches/bleeding_edge/src/platform-win32.cc       Mon Mar 12 09:10:53 2012
+++ /branches/bleeding_edge/src/platform-win32.cc       Mon Mar 12 10:15:13 2012
@@ -175,19 +175,16 @@
 #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();
+}
+
 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 +205,15 @@
 #endif  // _WIN64


-static LazyMutex math_function_mutex = LAZY_MUTEX_INITIALIZER;
-
 #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;                    \
+}                                                        \
 double fast_##name(double x) {                           \
-  if (fast_##name##_function == NULL) {                  \
-    ScopedLock lock(math_function_mutex.Pointer());      \
-    UnaryMathFunction temp = generator;                  \
-    MemoryBarrier();                                     \
-    fast_##name##_function = temp;                       \
-  }                                                      \
+  CallOnce(&fast_##name##_init_once,                     \
+           &init_fast_##name##_function);                \
   return (*fast_##name##_function)(x);                   \
 }

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to