Commit 5513631a authored by ssid@chromium.org's avatar ssid@chromium.org

Fix race at GCInfo::index.

This is a fix for the data race in GCInfoAtBase::index.
The GCInfo is defined as static local and this causes race while
allocating new objects. This CL reduces the initialization time by
using function pointer to get the class name instead of string parsing.

BUG=524237

Review URL: https://codereview.chromium.org/1312963002

git-svn-id: svn://svn.chromium.org/blink/trunk@201223 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 36a5fbca
...@@ -111,15 +111,16 @@ extern PLATFORM_EXPORT GCInfo const** s_gcInfoTable; ...@@ -111,15 +111,16 @@ extern PLATFORM_EXPORT GCInfo const** s_gcInfoTable;
// reachable. There is a GCInfo struct for each class that directly // reachable. There is a GCInfo struct for each class that directly
// inherits from GarbageCollected or GarbageCollectedFinalized. // inherits from GarbageCollected or GarbageCollectedFinalized.
struct GCInfo { struct GCInfo {
using GetClassNameCallback = const String (*)();
bool hasFinalizer() const { return m_nonTrivialFinalizer; } bool hasFinalizer() const { return m_nonTrivialFinalizer; }
bool hasVTable() const { return m_hasVTable; } bool hasVTable() const { return m_hasVTable; }
const String& className() const { return m_className; } const String className() const { return m_className(); }
TraceCallback m_trace; TraceCallback m_trace;
FinalizationCallback m_finalize; FinalizationCallback m_finalize;
bool m_nonTrivialFinalizer; bool m_nonTrivialFinalizer;
bool m_hasVTable; bool m_hasVTable;
// |m_className| is held as a reference to prevent dtor being called at exit. GetClassNameCallback m_className;
const String& m_className;
}; };
#if ENABLE(ASSERT) #if ENABLE(ASSERT)
...@@ -171,7 +172,7 @@ struct GCInfoAtBase { ...@@ -171,7 +172,7 @@ struct GCInfoAtBase {
FinalizerTrait<T>::finalize, FinalizerTrait<T>::finalize,
FinalizerTrait<T>::nonTrivialFinalizer, FinalizerTrait<T>::nonTrivialFinalizer,
WTF::IsPolymorphic<T>::value, WTF::IsPolymorphic<T>::value,
TypenameStringTrait<T>::get() TypenameStringTrait<T>::get
}; };
RETURN_GCINFO_INDEX(); RETURN_GCINFO_INDEX();
} }
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include "wtf/HashMap.h" #include "wtf/HashMap.h"
#include "wtf/HashTraits.h" #include "wtf/HashTraits.h"
#include "wtf/InstanceCounter.h" #include "wtf/InstanceCounter.h"
#include "wtf/Threading.h"
#include "wtf/TypeTraits.h" #include "wtf/TypeTraits.h"
#include "wtf/text/WTFString.h" #include "wtf/text/WTFString.h"
...@@ -387,11 +386,9 @@ private: ...@@ -387,11 +386,9 @@ private:
template<typename T> template<typename T>
struct TypenameStringTrait { struct TypenameStringTrait {
// This method is not thread safe. static const String get()
static const String& get()
{ {
AtomicallyInitializedStaticReference(AtomicString, typenameString, new AtomicString(WTF::extractTypeNameFromFunctionName(WTF::extractNameFunction<T>()))); return WTF::extractTypeNameFromFunctionName(WTF::extractNameFunction<T>());
return typenameString;
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment