Title: [141812] trunk/Source/WTF
- Revision
- 141812
- Author
- [email protected]
- Date
- 2013-02-04 14:20:46 -0800 (Mon, 04 Feb 2013)
Log Message
Upstream iOS's AtomicString
https://bugs.webkit.org/show_bug.cgi?id=108139
Reviewed by David Kilzer.
On iOS, WebCore can be executed from two different threads. To maintain consistency,
a few changes had been made:
-The main UI thread and the WebThread share the same AtomicStringTable.
-A spin lock is needed before any access to prevent any concurrent modification of the string table.
The spin lock also prevent race on the static initialization of the shared table.
* wtf/Platform.h:
Introduce a new USE(WEB_THREAD) to scope changes related to iOS Web Thread.
* wtf/text/AtomicString.cpp:
(AtomicStringTableLocker):
(WTF::AtomicStringTableLocker::AtomicStringTableLocker):
(WTF::AtomicStringTableLocker::~AtomicStringTableLocker):
(WTF::AtomicStringTable::create):
wtfThreadData() is not necessarily inlined on ARM. When it is not inlined, the old code
causes two call to the function. Instead, we can keep the value in register and pass it
to AtomicStringTable::create().
(WTF::stringTable):
(WTF::addToStringTable):
(WTF::AtomicString::addSlowCase):
(WTF::AtomicString::find):
(WTF::AtomicString::remove):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (141811 => 141812)
--- trunk/Source/WTF/ChangeLog 2013-02-04 22:19:48 UTC (rev 141811)
+++ trunk/Source/WTF/ChangeLog 2013-02-04 22:20:46 UTC (rev 141812)
@@ -1,3 +1,32 @@
+2013-02-04 Benjamin Poulain <[email protected]>
+
+ Upstream iOS's AtomicString
+ https://bugs.webkit.org/show_bug.cgi?id=108139
+
+ Reviewed by David Kilzer.
+
+ On iOS, WebCore can be executed from two different threads. To maintain consistency,
+ a few changes had been made:
+ -The main UI thread and the WebThread share the same AtomicStringTable.
+ -A spin lock is needed before any access to prevent any concurrent modification of the string table.
+ The spin lock also prevent race on the static initialization of the shared table.
+
+ * wtf/Platform.h:
+ Introduce a new USE(WEB_THREAD) to scope changes related to iOS Web Thread.
+ * wtf/text/AtomicString.cpp:
+ (AtomicStringTableLocker):
+ (WTF::AtomicStringTableLocker::AtomicStringTableLocker):
+ (WTF::AtomicStringTableLocker::~AtomicStringTableLocker):
+ (WTF::AtomicStringTable::create):
+ wtfThreadData() is not necessarily inlined on ARM. When it is not inlined, the old code
+ causes two call to the function. Instead, we can keep the value in register and pass it
+ to AtomicStringTable::create().
+ (WTF::stringTable):
+ (WTF::addToStringTable):
+ (WTF::AtomicString::addSlowCase):
+ (WTF::AtomicString::find):
+ (WTF::AtomicString::remove):
+
2013-02-04 Martin Robinson <[email protected]>
Fix GTK+ 'make dist' in preparation for the 1.11.5 release.
Modified: trunk/Source/WTF/wtf/Platform.h (141811 => 141812)
--- trunk/Source/WTF/wtf/Platform.h 2013-02-04 22:19:48 UTC (rev 141811)
+++ trunk/Source/WTF/wtf/Platform.h 2013-02-04 22:20:46 UTC (rev 141812)
@@ -617,6 +617,7 @@
#define WTF_USE_CFNETWORK 1
#define WTF_USE_NETWORK_CFDATA_ARRAY_CALLBACK 1
#define WTF_USE_PTHREADS 1
+#define WTF_USE_WEB_THREAD 1
#if PLATFORM(IOS_SIMULATOR)
#define ENABLE_JIT 0
Modified: trunk/Source/WTF/wtf/text/AtomicString.cpp (141811 => 141812)
--- trunk/Source/WTF/wtf/text/AtomicString.cpp 2013-02-04 22:19:48 UTC (rev 141811)
+++ trunk/Source/WTF/wtf/text/AtomicString.cpp 2013-02-04 22:20:46 UTC (rev 141812)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2010 Patrick Gansterer <[email protected]>
* Copyright (C) 2012 Google Inc. All rights reserved.
*
@@ -30,24 +30,64 @@
#include <wtf/WTFThreadData.h>
#include <wtf/unicode/UTF8.h>
+#if USE(WEB_THREAD)
+#include <wtf/MainThread.h>
+#include <wtf/TCSpinLock.h>
+#endif
+
namespace WTF {
using namespace Unicode;
COMPILE_ASSERT(sizeof(AtomicString) == sizeof(String), atomic_string_and_string_must_be_same_size);
+#if USE(WEB_THREAD)
+class AtomicStringTableLocker : public SpinLockHolder {
+ WTF_MAKE_NONCOPYABLE(AtomicStringTableLocker);
+
+ static SpinLock s_stringTableLock;
+public:
+ AtomicStringTableLocker()
+ : SpinLockHolder(&s_stringTableLock)
+ {
+ }
+};
+
+SpinLock AtomicStringTableLocker::s_stringTableLock = SPINLOCK_INITIALIZER;
+#else
+
+class AtomicStringTableLocker {
+ WTF_MAKE_NONCOPYABLE(AtomicStringTableLocker);
+public:
+ AtomicStringTableLocker() { }
+ ~AtomicStringTableLocker() { }
+};
+#endif // USE(WEB_THREAD)
+
class AtomicStringTable {
WTF_MAKE_FAST_ALLOCATED;
public:
- static AtomicStringTable* create()
+ static AtomicStringTable* create(WTFThreadData& data)
{
- AtomicStringTable* table = new AtomicStringTable;
+#if USE(WEB_THREAD)
+ // On iOS, one AtomicStringTable is shared between the main UI thread and the WebThread.
+ static AtomicStringTable* sharedStringTable = new AtomicStringTable;
- WTFThreadData& data = ""
- data.m_atomicStringTable = table;
+ bool currentThreadIsWebThread = isWebThread();
+ if (currentThreadIsWebThread || isUIThread())
+ data.m_atomicStringTable = sharedStringTable;
+ else
+ data.m_atomicStringTable = new AtomicStringTable;
+
+ // We do the following so that its destruction happens only
+ // once - on the main UI thread.
+ if (!currentThreadIsWebThread)
+ data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
+#else
+ data.m_atomicStringTable = new AtomicStringTable;
data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
-
- return table;
+#endif // USE(WEB_THREAD)
+ return data.m_atomicStringTable;
}
HashSet<StringImpl*>& table()
@@ -70,15 +110,18 @@
static inline HashSet<StringImpl*>& stringTable()
{
// Once possible we should make this non-lazy (constructed in WTFThreadData's constructor).
- AtomicStringTable* table = wtfThreadData().atomicStringTable();
+ WTFThreadData& data = ""
+ AtomicStringTable* table = data.atomicStringTable();
if (UNLIKELY(!table))
- table = AtomicStringTable::create();
+ table = AtomicStringTable::create(data);
return table->table();
}
template<typename T, typename HashTranslator>
static inline PassRefPtr<StringImpl> addToStringTable(const T& value)
{
+ AtomicStringTableLocker locker;
+
HashSet<StringImpl*>::AddResult addResult = stringTable().add<T, HashTranslator>(value);
// If the string is newly-translated, then we need to adopt it.
@@ -386,6 +429,7 @@
if (!r->length())
return StringImpl::empty();
+ AtomicStringTableLocker locker;
StringImpl* result = *stringTable().add(r).iterator;
if (result == r)
r->setIsAtomic(true);
@@ -407,6 +451,7 @@
if (!stringImpl->length())
return static_cast<AtomicStringImpl*>(StringImpl::empty());
+ AtomicStringTableLocker locker;
HashSet<StringImpl*>::iterator iterator;
if (stringImpl->is8Bit())
iterator = findString<LChar>(stringImpl);
@@ -419,6 +464,7 @@
void AtomicString::remove(StringImpl* r)
{
+ AtomicStringTableLocker locker;
stringTable().remove(r);
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes