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;
// reachable. There is a GCInfo struct for each class that directly
// inherits from GarbageCollected or GarbageCollectedFinalized.
struct GCInfo {
using GetClassNameCallback = const String (*)();
bool hasFinalizer() const { return m_nonTrivialFinalizer; }
bool hasVTable() const { return m_hasVTable; }
const String& className() const { return m_className; }
const String className() const { return m_className(); }
TraceCallback m_trace;
FinalizationCallback m_finalize;
bool m_nonTrivialFinalizer;
bool m_hasVTable;
// |m_className| is held as a reference to prevent dtor being called at exit.
const String& m_className;
GetClassNameCallback m_className;
};
#if ENABLE(ASSERT)
......@@ -171,7 +172,7 @@ struct GCInfoAtBase {
FinalizerTrait<T>::finalize,
FinalizerTrait<T>::nonTrivialFinalizer,
WTF::IsPolymorphic<T>::value,
TypenameStringTrait<T>::get()
TypenameStringTrait<T>::get
};
RETURN_GCINFO_INDEX();
}
......
......@@ -42,7 +42,6 @@
#include "wtf/HashMap.h"
#include "wtf/HashTraits.h"
#include "wtf/InstanceCounter.h"
#include "wtf/Threading.h"
#include "wtf/TypeTraits.h"
#include "wtf/text/WTFString.h"
......@@ -387,11 +386,9 @@ private:
template<typename T>
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 typenameString;
return WTF::extractTypeNameFromFunctionName(WTF::extractNameFunction<T>());
}
};
......
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