From 9a110acaa8ebfadc8065f7e340c29dc9f13f8fcd Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Mon, 12 Mar 2012 17:15:13 +0000 Subject: [PATCH] Remove static Mutex from math function intializers. BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/9662064 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11015 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/platform-posix.cc | 14 ++++++-------- src/platform-win32.cc | 29 ++++++++++++----------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/platform-posix.cc b/src/platform-posix.cc index 34b19d732b..a729b66260 100644 --- a/src/platform-posix.cc +++ b/src/platform-posix.cc @@ -127,17 +127,15 @@ double modulo(double x, double y) { } -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); \ } diff --git a/src/platform-win32.cc b/src/platform-win32.cc index 16a5b0bc8a..5600542ba0 100644 --- a/src/platform-win32.cc +++ b/src/platform-win32.cc @@ -175,19 +175,16 @@ 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(); +} + 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 @@ double modulo(double x, double y) { #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); \ }