summaryrefslogtreecommitdiffstats
path: root/WebCore/dom/EventNames.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/dom/EventNames.cpp')
-rw-r--r--WebCore/dom/EventNames.cpp57
1 files changed, 40 insertions, 17 deletions
diff --git a/WebCore/dom/EventNames.cpp b/WebCore/dom/EventNames.cpp
index c5aaa37..22a716d 100644
--- a/WebCore/dom/EventNames.cpp
+++ b/WebCore/dom/EventNames.cpp
@@ -21,31 +21,54 @@
*/
#include "config.h"
+#include "EventNames.h"
+
+#include <wtf/Threading.h>
-#ifdef AVOID_STATIC_CONSTRUCTORS
-#define DOM_EVENT_NAMES_HIDE_GLOBALS 1
+#if ENABLE(WORKERS)
+#include <wtf/ThreadSpecific.h>
+using namespace WTF;
#endif
-#include "EventNames.h"
-#include "StaticConstructors.h"
+namespace WebCore {
-namespace WebCore { namespace EventNames {
+#if ENABLE(WORKERS)
+static ThreadSpecific<EventNames>* staticEventNames;
+#else
+static EventNames* staticEventNames;
+#endif
+
+#define INITIALIZE_EVENT_NAME(name) \
+ , name##Event(#name)
+EventNames::EventNames()
+ : dummy(0)
+DOM_EVENT_NAMES_FOR_EACH(INITIALIZE_EVENT_NAME)
+{
+}
-#define DEFINE_EVENT_GLOBAL(name) \
- DEFINE_GLOBAL(AtomicString, name##Event, #name)
-DOM_EVENT_NAMES_FOR_EACH(DEFINE_EVENT_GLOBAL)
+EventNames& eventNames()
+{
+#if ENABLE(WORKERS)
+ return **staticEventNames;
+#else
+ return *staticEventNames;
+#endif
+}
-void init()
+void EventNames::init()
{
- static bool initialized;
- if (!initialized) {
- // Use placement new to initialize the globals.
-
+ if (!staticEventNames) {
+ // Initialization is not thread safe, so this function must be called from the main thread first.
+ ASSERT(isMainThread());
+
AtomicString::init();
- #define INITIALIZE_GLOBAL(name) new ((void*)&name##Event) AtomicString(#name);
- DOM_EVENT_NAMES_FOR_EACH(INITIALIZE_GLOBAL)
- initialized = true;
+
+#if ENABLE(WORKERS)
+ staticEventNames = new ThreadSpecific<EventNames>;
+#else
+ staticEventNames = new EventNames;
+#endif
}
}
-} }
+}