Replace TCSpinLock with a new WTF::SpinLock based on WTF::Atomic.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Mar 2015 20:04:29 +0000 (20:04 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Mar 2015 20:04:29 +0000 (20:04 +0000)
<https://webkit.org/b/142674>

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

* API/JSValue.mm:
(handerForStructTag):
* API/JSWrapperMap.mm:
* dfg/DFGCommon.cpp:
(JSC::DFG::startCrashing):
(JSC::DFG::isCrashing):
- Changed to use a StaticSpinLock since that's what this code was trying to do
  anyway.
* heap/CopiedBlock.h:
(JSC::CopiedBlock::CopiedBlock):
* heap/CopiedSpace.cpp:
(JSC::CopiedSpace::CopiedSpace):
* heap/CopiedSpace.h:
* heap/GCThreadSharedData.cpp:
(JSC::GCThreadSharedData::GCThreadSharedData):
* heap/GCThreadSharedData.h:
* heap/ListableHandler.h:
(JSC::ListableHandler::List::List):
* parser/SourceProvider.cpp:
* profiler/ProfilerDatabase.cpp:
(JSC::Profiler::Database::addDatabaseToAtExit):
(JSC::Profiler::Database::removeDatabaseFromAtExit):
(JSC::Profiler::Database::removeFirstAtExitDatabase):

Source/WebCore:

No new tests because there is no new functionality. This is a refactoring effort.

* bindings/objc/WebScriptObject.mm:
* platform/ios/wak/WAKWindow.mm:
(-[WAKWindow initWithLayer:]):
(-[WAKWindow initWithFrame:]):

Source/WebKit2:

* WebProcess/WebPage/EventDispatcher.cpp:
(WebKit::EventDispatcher::EventDispatcher):
* WebProcess/WebPage/EventDispatcher.h:
* WebProcess/WebPage/ViewUpdateDispatcher.cpp:
(WebKit::ViewUpdateDispatcher::ViewUpdateDispatcher):
* WebProcess/WebPage/ViewUpdateDispatcher.h:

Source/WTF:

We no longer use TCMalloc in our code, and we now have C++11.  This replaces the
TCMalloc_SpinLock with a new WTF::SpinLock based on WTF::Atomic (which is a
wrapper around std::atomic).

Note that there is a StaticSpinLock and a SpinLock:

1. StaticSpinLock is an alias for SpinLockBase, and its initialization relies on
   static / global std:atomic being automatically initialized to 0 at compile time.
   Hence, StaticSpinLock should only be used for statics / globals (including
   static members of classes / structs).

2. SpinLock is derived from SpinLockBase, and adds a default constructor to
   initialize its internal atomic value to 0.  Because SpinLock has a constructor,
   it cannot be used for statics / globals.  Objects that want to embed a spin
   lock as an instance field should use SpinLock so that it is initialized properly.
   std::atomic will not automatically initialize instance fields to 0.  Hence,
   StaticSpinLock will not work correctly as instance fields of a class / struct.

* WTF.vcxproj/WTF.vcxproj:
* WTF.vcxproj/WTF.vcxproj.filters:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/MetaAllocator.cpp:
(WTF::MetaAllocator::~MetaAllocator):
(WTF::MetaAllocator::MetaAllocator):
* wtf/MetaAllocator.h:
* wtf/SpinLock.h: Added.
(WTF::SpinLockBase::lock):
(WTF::SpinLockBase::unlock):
(WTF::SpinLockBase::isLocked):
(WTF::SpinLockBase::slowLock):
(WTF::SpinLock::SpinLock):
* wtf/TCSpinLock.h: Removed.
* wtf/text/AtomicString.cpp:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181485 268f45cc-cd09-0410-ab3c-d52691b4dbfc

30 files changed:
Source/JavaScriptCore/API/JSValue.mm
Source/JavaScriptCore/API/JSWrapperMap.mm
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/dfg/DFGCommon.cpp
Source/JavaScriptCore/heap/CopiedBlock.h
Source/JavaScriptCore/heap/CopiedSpace.cpp
Source/JavaScriptCore/heap/CopiedSpace.h
Source/JavaScriptCore/heap/GCThreadSharedData.cpp
Source/JavaScriptCore/heap/GCThreadSharedData.h
Source/JavaScriptCore/heap/ListableHandler.h
Source/JavaScriptCore/parser/SourceProvider.cpp
Source/JavaScriptCore/profiler/ProfilerDatabase.cpp
Source/WTF/ChangeLog
Source/WTF/WTF.vcxproj/WTF.vcxproj
Source/WTF/WTF.vcxproj/WTF.vcxproj.filters
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/MetaAllocator.cpp
Source/WTF/wtf/MetaAllocator.h
Source/WTF/wtf/SpinLock.h [new file with mode: 0644]
Source/WTF/wtf/TCSpinLock.h [deleted file]
Source/WTF/wtf/text/AtomicString.cpp
Source/WebCore/ChangeLog
Source/WebCore/bindings/objc/WebScriptObject.mm
Source/WebCore/platform/ios/wak/WAKWindow.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/EventDispatcher.cpp
Source/WebKit2/WebProcess/WebPage/EventDispatcher.h
Source/WebKit2/WebProcess/WebPage/ViewUpdateDispatcher.cpp
Source/WebKit2/WebProcess/WebPage/ViewUpdateDispatcher.h

index c2dc514..0cbe1f1 100644 (file)
@@ -41,8 +41,8 @@
 #import <wtf/HashMap.h>
 #import <wtf/HashSet.h>
 #import <wtf/ObjcRuntimeExtras.h>
+#import <wtf/SpinLock.h>
 #import <wtf/Vector.h>
-#import <wtf/TCSpinLock.h>
 #import <wtf/text/WTFString.h>
 #import <wtf/text/StringHash.h>
 
@@ -1102,7 +1102,7 @@ static StructHandlers* createStructHandlerMap()
 
 static StructTagHandler* handerForStructTag(const char* encodedType)
 {
-    static SpinLock handerForStructTagLock = SPINLOCK_INITIALIZER;
+    static StaticSpinLock handerForStructTagLock;
     SpinLockHolder lockHolder(&handerForStructTagLock);
 
     static StructHandlers* structHandlers = createStructHandlerMap();
index 2451715..2cb0ec1 100644 (file)
@@ -39,7 +39,6 @@
 #import "WeakGCMap.h"
 #import "WeakGCMapInlines.h"
 #import <wtf/HashSet.h>
-#import <wtf/TCSpinLock.h>
 #import <wtf/Vector.h>
 #import <wtf/spi/cocoa/NSMapTableSPI.h>
 
index ac83470..68ba5f5 100644 (file)
@@ -1,3 +1,34 @@
+2015-03-13  Mark Lam  <mark.lam@apple.com>
+
+        Replace TCSpinLock with a new WTF::SpinLock based on WTF::Atomic.
+        <https://webkit.org/b/142674>
+
+        Reviewed by Filip Pizlo.
+
+        * API/JSValue.mm:
+        (handerForStructTag):
+        * API/JSWrapperMap.mm:
+        * dfg/DFGCommon.cpp:
+        (JSC::DFG::startCrashing):
+        (JSC::DFG::isCrashing):
+        - Changed to use a StaticSpinLock since that's what this code was trying to do
+          anyway.
+        * heap/CopiedBlock.h:
+        (JSC::CopiedBlock::CopiedBlock):
+        * heap/CopiedSpace.cpp:
+        (JSC::CopiedSpace::CopiedSpace):
+        * heap/CopiedSpace.h:
+        * heap/GCThreadSharedData.cpp:
+        (JSC::GCThreadSharedData::GCThreadSharedData):
+        * heap/GCThreadSharedData.h:
+        * heap/ListableHandler.h:
+        (JSC::ListableHandler::List::List):
+        * parser/SourceProvider.cpp:
+        * profiler/ProfilerDatabase.cpp:
+        (JSC::Profiler::Database::addDatabaseToAtExit):
+        (JSC::Profiler::Database::removeDatabaseFromAtExit):
+        (JSC::Profiler::Database::removeFirstAtExitDatabase):
+
 2015-03-13  Ryosuke Niwa  <rniwa@webkit.org>
 
         BytecodeGenerator needs to be re-entrant to support miranda functions
index c2cb53b..04aeed1 100644 (file)
 
 namespace JSC { namespace DFG {
 
-static Atomic<unsigned> crashLock;
+static StaticSpinLock crashLock;
 
 void startCrashing()
 {
-    while (!crashLock.compare_exchange_weak(0, 1, std::memory_order_acquire))
-        std::this_thread::yield();
+    crashLock.lock();
 }
 
 bool isCrashing()
 {
-    return !!crashLock.load(std::memory_order_acquire);
+    return crashLock.isLocked();
 }
 
 } } // namespace JSC::DFG
index fc199bd..25762f0 100644 (file)
@@ -32,7 +32,7 @@
 #include "Options.h"
 #include <wtf/Atomics.h>
 #include <wtf/DoublyLinkedList.h>
-#include <wtf/TCSpinLock.h>
+#include <wtf/SpinLock.h>
 
 namespace JSC {
 
@@ -152,7 +152,6 @@ inline CopiedBlock::CopiedBlock(size_t capacity)
     , m_liveObjects(0)
 #endif
 {
-    m_workListLock.Init();
     ASSERT(is8ByteAligned(reinterpret_cast<void*>(m_remaining)));
 }
 
index c356b91..ec13af7 100644 (file)
@@ -39,7 +39,6 @@ CopiedSpace::CopiedSpace(Heap* heap)
     , m_shouldDoCopyPhase(false)
     , m_numberOfLoanedBlocks(0)
 {
-    m_toSpaceLock.Init();
 }
 
 CopiedSpace::~CopiedSpace()
index c0a59a2..30ba736 100644 (file)
@@ -37,8 +37,8 @@
 #include <wtf/OSAllocator.h>
 #include <wtf/PageAllocationAligned.h>
 #include <wtf/PageBlock.h>
+#include <wtf/SpinLock.h>
 #include <wtf/StdLibExtras.h>
-#include <wtf/TCSpinLock.h>
 #include <wtf/ThreadingPrimitives.h>
 
 namespace JSC {
index c8847aa..2427ecb 100644 (file)
@@ -81,7 +81,6 @@ GCThreadSharedData::GCThreadSharedData(VM* vm)
     , m_gcThreadsShouldWait(false)
     , m_currentPhase(NoPhase)
 {
-    m_copyLock.Init();
 #if ENABLE(PARALLEL_GC)
     // Grab the lock so the new GC threads can be properly initialized before they start running.
     std::unique_lock<std::mutex> lock(m_phaseMutex);
index 3e5037c..d6c960a 100644 (file)
@@ -33,7 +33,7 @@
 #include "WeakReferenceHarvester.h"
 #include <condition_variable>
 #include <wtf/HashSet.h>
-#include <wtf/TCSpinLock.h>
+#include <wtf/SpinLock.h>
 #include <wtf/Vector.h>
 
 namespace JSC {
index 16c3414..560a356 100644 (file)
@@ -23,8 +23,8 @@
 #include <stdint.h>
 #include <wtf/Locker.h>
 #include <wtf/Noncopyable.h>
+#include <wtf/SpinLock.h>
 #include <wtf/ThreadingPrimitives.h>
-#include <wtf/TCSpinLock.h>
 
 namespace JSC {
 
@@ -61,7 +61,6 @@ private:
         List()
             : m_first(0)
         {
-            m_lock.Init();
         }
         
         void addThreadSafe(T* handler)
index 939addf..c965245 100644 (file)
@@ -27,8 +27,8 @@
 #include "SourceProvider.h"
 
 #include "JSCInlines.h"
+#include <wtf/SpinLock.h>
 #include <wtf/StdLibExtras.h>
-#include <wtf/TCSpinLock.h>
 
 namespace JSC {
 
@@ -44,7 +44,7 @@ SourceProvider::~SourceProvider()
 {
 }
 
-static TCMalloc_SpinLock providerIdLock = SPINLOCK_INITIALIZER;
+static StaticSpinLock providerIdLock;
 
 void SourceProvider::getID()
 {
index 3d5a2ee..236a5c8 100644 (file)
@@ -35,7 +35,7 @@ namespace JSC { namespace Profiler {
 
 static std::atomic<int> databaseCounter;
 
-static SpinLock registrationLock = SPINLOCK_INITIALIZER;
+static StaticSpinLock registrationLock;
 static std::atomic<int> didRegisterAtExit;
 static Database* firstDatabase;
 
@@ -138,14 +138,14 @@ void Database::addDatabaseToAtExit()
     if (++didRegisterAtExit == 1)
         atexit(atExitCallback);
     
-    TCMalloc_SpinLockHolder holder(&registrationLock);
+    SpinLockHolder holder(registrationLock);
     m_nextRegisteredDatabase = firstDatabase;
     firstDatabase = this;
 }
 
 void Database::removeDatabaseFromAtExit()
 {
-    TCMalloc_SpinLockHolder holder(&registrationLock);
+    SpinLockHolder holder(registrationLock);
     for (Database** current = &firstDatabase; *current; current = &(*current)->m_nextRegisteredDatabase) {
         if (*current != this)
             continue;
@@ -163,7 +163,7 @@ void Database::performAtExitSave() const
 
 Database* Database::removeFirstAtExitDatabase()
 {
-    TCMalloc_SpinLockHolder holder(&registrationLock);
+    SpinLockHolder holder(registrationLock);
     Database* result = firstDatabase;
     if (result) {
         firstDatabase = result->m_nextRegisteredDatabase;
index 0b3655e..61b06fa 100644 (file)
@@ -1,5 +1,47 @@
 2015-03-13  Mark Lam  <mark.lam@apple.com>
 
+        Replace TCSpinLock with a new WTF::SpinLock based on WTF::Atomic.
+        <https://webkit.org/b/142674>
+
+        Reviewed by Filip Pizlo.
+
+        We no longer use TCMalloc in our code, and we now have C++11.  This replaces the
+        TCMalloc_SpinLock with a new WTF::SpinLock based on WTF::Atomic (which is a
+        wrapper around std::atomic).
+
+        Note that there is a StaticSpinLock and a SpinLock:
+
+        1. StaticSpinLock is an alias for SpinLockBase, and its initialization relies on
+           static / global std:atomic being automatically initialized to 0 at compile time.
+           Hence, StaticSpinLock should only be used for statics / globals (including
+           static members of classes / structs).
+
+        2. SpinLock is derived from SpinLockBase, and adds a default constructor to
+           initialize its internal atomic value to 0.  Because SpinLock has a constructor,
+           it cannot be used for statics / globals.  Objects that want to embed a spin
+           lock as an instance field should use SpinLock so that it is initialized properly.
+           std::atomic will not automatically initialize instance fields to 0.  Hence,
+           StaticSpinLock will not work correctly as instance fields of a class / struct.
+
+        * WTF.vcxproj/WTF.vcxproj:
+        * WTF.vcxproj/WTF.vcxproj.filters:
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/CMakeLists.txt:
+        * wtf/MetaAllocator.cpp:
+        (WTF::MetaAllocator::~MetaAllocator):
+        (WTF::MetaAllocator::MetaAllocator):
+        * wtf/MetaAllocator.h:
+        * wtf/SpinLock.h: Added.
+        (WTF::SpinLockBase::lock):
+        (WTF::SpinLockBase::unlock):
+        (WTF::SpinLockBase::isLocked):
+        (WTF::SpinLockBase::slowLock):
+        (WTF::SpinLock::SpinLock):
+        * wtf/TCSpinLock.h: Removed.
+        * wtf/text/AtomicString.cpp:
+
+2015-03-13  Mark Lam  <mark.lam@apple.com>
+
         Introduce WTF::Atomic to wrap std::atomic for a friendlier CAS.
         <https://webkit.org/b/142661>
 
index 694639c..f57cea6 100644 (file)
     <ClInclude Include="..\wtf\SHA1.h" />
     <ClInclude Include="..\wtf\SinglyLinkedList.h" />
     <ClInclude Include="..\wtf\SixCharacterHash.h" />
+    <ClInclude Include="..\wtf\SpinLock.h" />
     <ClInclude Include="..\wtf\StackBounds.h" />
     <ClInclude Include="..\wtf\StaticConstructors.h" />
     <ClInclude Include="..\wtf\StdLibExtras.h" />
     <ClInclude Include="..\wtf\StringExtras.h" />
     <ClInclude Include="..\wtf\StringHasher.h" />
     <ClInclude Include="..\wtf\StringPrintStream.h" />
-    <ClInclude Include="..\wtf\TCSpinLock.h" />
     <ClInclude Include="..\wtf\TemporaryChange.h" />
     <ClInclude Include="..\wtf\text\ASCIIFastPath.h" />
     <ClInclude Include="..\wtf\text\AtomicString.h" />
index f46d4d4..2493e5a 100644 (file)
     <ClInclude Include="..\wtf\SinglyLinkedList.h">
       <Filter>wtf</Filter>
     </ClInclude>
+    <ClInclude Include="..\wtf\SpinLock.h">
+      <Filter>wtf</Filter>
+    </ClInclude>
     <ClInclude Include="..\wtf\StackBounds.h">
       <Filter>wtf</Filter>
     </ClInclude>
     <ClInclude Include="..\wtf\StringPrintStream.h">
       <Filter>wtf</Filter>
     </ClInclude>
-    <ClInclude Include="..\wtf\TCSpinLock.h">
-      <Filter>wtf</Filter>
-    </ClInclude>
     <ClInclude Include="..\wtf\TemporaryChange.h">
       <Filter>wtf</Filter>
     </ClInclude>
index f7df2ea..744b70a 100644 (file)
                A8A4742A151A825B004123FF /* StdLibExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47311151A825B004123FF /* StdLibExtras.h */; };
                A8A4742C151A825B004123FF /* StringExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47313151A825B004123FF /* StringExtras.h */; };
                A8A4742D151A825B004123FF /* StringHasher.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47314151A825B004123FF /* StringHasher.h */; };
-               A8A47430151A825B004123FF /* TCSpinLock.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47317151A825B004123FF /* TCSpinLock.h */; };
                A8A47433151A825B004123FF /* TemporaryChange.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A4731A151A825B004123FF /* TemporaryChange.h */; };
                A8A47434151A825B004123FF /* ASCIIFastPath.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A4731C151A825B004123FF /* ASCIIFastPath.h */; };
                A8A47435151A825B004123FF /* AtomicString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A4731D151A825B004123FF /* AtomicString.cpp */; };
                E4A0AD3A1A96245500536DF6 /* WorkQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = E4A0AD381A96245500536DF6 /* WorkQueue.h */; };
                E4A0AD3D1A96253C00536DF6 /* WorkQueueCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4A0AD3C1A96253C00536DF6 /* WorkQueueCocoa.cpp */; };
                EB95E1F0161A72410089A2F5 /* ByteOrder.h in Headers */ = {isa = PBXBuildFile; fileRef = EB95E1EF161A72410089A2F5 /* ByteOrder.h */; };
+               FE91E8811AB2A0200099895F /* SpinLock.h in Headers */ = {isa = PBXBuildFile; fileRef = FE91E8801AB2A0200099895F /* SpinLock.h */; };
                FEDACD3D1630F83F00C69634 /* StackStats.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEDACD3B1630F83F00C69634 /* StackStats.cpp */; };
                FEDACD3E1630F83F00C69634 /* StackStats.h in Headers */ = {isa = PBXBuildFile; fileRef = FEDACD3C1630F83F00C69634 /* StackStats.h */; };
 /* End PBXBuildFile section */
                A8A47311151A825B004123FF /* StdLibExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StdLibExtras.h; sourceTree = "<group>"; };
                A8A47313151A825B004123FF /* StringExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringExtras.h; sourceTree = "<group>"; };
                A8A47314151A825B004123FF /* StringHasher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringHasher.h; sourceTree = "<group>"; };
-               A8A47317151A825B004123FF /* TCSpinLock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TCSpinLock.h; sourceTree = "<group>"; };
                A8A4731A151A825B004123FF /* TemporaryChange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TemporaryChange.h; sourceTree = "<group>"; };
                A8A4731C151A825B004123FF /* ASCIIFastPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASCIIFastPath.h; sourceTree = "<group>"; };
                A8A4731D151A825B004123FF /* AtomicString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomicString.cpp; sourceTree = "<group>"; };
                E4A0AD381A96245500536DF6 /* WorkQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkQueue.h; sourceTree = "<group>"; };
                E4A0AD3C1A96253C00536DF6 /* WorkQueueCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueueCocoa.cpp; sourceTree = "<group>"; };
                EB95E1EF161A72410089A2F5 /* ByteOrder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ByteOrder.h; sourceTree = "<group>"; };
+               FE91E8801AB2A0200099895F /* SpinLock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpinLock.h; sourceTree = "<group>"; };
                FEDACD3B1630F83F00C69634 /* StackStats.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StackStats.cpp; sourceTree = "<group>"; };
                FEDACD3C1630F83F00C69634 /* StackStats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StackStats.h; sourceTree = "<group>"; };
 /* End PBXFileReference section */
                                A748745017A0BDAE00FA04CB /* SixCharacterHash.h */,
                                A8A4730C151A825B004123FF /* SizeLimits.cpp */,
                                A8A4730D151A825B004123FF /* Spectrum.h */,
+                               FE91E8801AB2A0200099895F /* SpinLock.h */,
                                A8A4730E151A825B004123FF /* StackBounds.cpp */,
                                A8A4730F151A825B004123FF /* StackBounds.h */,
                                FEDACD3B1630F83F00C69634 /* StackStats.cpp */,
                                A8A47314151A825B004123FF /* StringHasher.h */,
                                0FDDBFA51666DFA300C55FEF /* StringPrintStream.cpp */,
                                0FDDBFA61666DFA300C55FEF /* StringPrintStream.h */,
-                               A8A47317151A825B004123FF /* TCSpinLock.h */,
                                A8A4731A151A825B004123FF /* TemporaryChange.h */,
                                A8A4732F151A825B004123FF /* ThreadFunctionInvocation.h */,
                                A8A47330151A825B004123FF /* ThreadIdentifierDataPthreads.cpp */,
                                A8A4743B151A825B004123FF /* StringBuffer.h in Headers */,
                                A8A4743D151A825B004123FF /* StringBuilder.h in Headers */,
                                A8A4743E151A825B004123FF /* StringConcatenate.h in Headers */,
+                               FE91E8811AB2A0200099895F /* SpinLock.h in Headers */,
                                A8A4742C151A825B004123FF /* StringExtras.h in Headers */,
                                A8A4743F151A825B004123FF /* StringHash.h in Headers */,
                                A748745417A0BDAE00FA04CB /* StringHashDumpContext.h in Headers */,
                                0FDDBFA81666DFA300C55FEF /* StringPrintStream.h in Headers */,
                                1AFDE6531953B23D00C48FFA /* Optional.h in Headers */,
                                A8A473B8151A825B004123FF /* strtod.h in Headers */,
-                               A8A47430151A825B004123FF /* TCSpinLock.h in Headers */,
                                E15556F618A0CC18006F48FB /* CryptographicUtilities.h in Headers */,
                                83FBA93219DF459700F30ADB /* TypeCasts.h in Headers */,
                                1A6EB1E0187D0BD30030126F /* StringView.h in Headers */,
index e3f92fe..0ed53bc 100644 (file)
@@ -87,6 +87,7 @@ set(WTF_HEADERS
     SHA1.h
     SaturatedArithmetic.h
     SegmentedVector.h
+    SpinLock.h
     StackBounds.h
     StackStats.h
     StaticConstructors.h
@@ -95,7 +96,6 @@ set(WTF_HEADERS
     StringExtras.h
     StringHasher.h
     StringPrintStream.h
-    TCSpinLock.h
     ThreadIdentifierDataPthreads.h
     ThreadSafeRefCounted.h
     ThreadSpecific.h
index f43ae9c..1e740ee 100644 (file)
@@ -43,7 +43,6 @@ MetaAllocator::~MetaAllocator()
         freeFreeSpaceNode(node);
         node = next;
     }
-    m_lock.Finalize();
 #ifndef NDEBUG
     ASSERT(!m_mallocBalance);
 #endif
@@ -129,8 +128,6 @@ MetaAllocator::MetaAllocator(size_t allocationGranule, size_t pageSize)
     , m_numFrees(0)
 #endif
 {
-    m_lock.Init();
-    
     for (m_logPageSize = 0; m_logPageSize < 32; ++m_logPageSize) {
         if (static_cast<size_t>(1) << m_logPageSize == m_pageSize)
             break;
index 6f8a21d..5a0f091 100644 (file)
@@ -37,7 +37,7 @@
 #include <wtf/RedBlackTree.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
-#include <wtf/TCSpinLock.h>
+#include <wtf/SpinLock.h>
 
 namespace WTF {
 
diff --git a/Source/WTF/wtf/SpinLock.h b/Source/WTF/wtf/SpinLock.h
new file mode 100644 (file)
index 0000000..73fa286
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SpinLock_h
+#define SpinLock_h
+
+#include <thread>
+#include <wtf/Atomics.h>
+#include <wtf/Locker.h>
+
+namespace WTF {
+
+// SpinLockBase is a struct without an explicitly defined constructors so that
+// it can be initialized at compile time. See StaticSpinLock below.
+struct SpinLockBase {
+
+    void lock()
+    {
+        while (!m_lock.compare_exchange_weak(0, 1, std::memory_order_acquire))
+            std::this_thread::yield();
+    }
+
+    void unlock()
+    {
+        m_lock.store(0, std::memory_order_release);
+    }
+
+    bool isLocked() const
+    {
+        return m_lock.load(std::memory_order_acquire);
+    }
+    
+    Atomic<unsigned> m_lock;
+};
+
+// SpinLock is for use as instance variables in structs and classes, not as
+// statics and globals.
+struct SpinLock : public SpinLockBase {
+    SpinLock()
+    {
+        m_lock.store(0, std::memory_order_relaxed);
+    }
+};
+
+// StaticSpinLock is for use as statics and globals, not as instance variables.
+typedef SpinLockBase StaticSpinLock;
+typedef Locker<SpinLockBase> SpinLockHolder;
+
+} // namespace WTF
+
+using WTF::StaticSpinLock;
+using WTF::SpinLock;
+using WTF::SpinLockHolder;
+
+#endif // SpinLock_h
diff --git a/Source/WTF/wtf/TCSpinLock.h b/Source/WTF/wtf/TCSpinLock.h
deleted file mode 100644 (file)
index d8eddcf..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright (c) 2005, 2006, Google Inc.
-// Copyright (c) 2010, Patrick Gansterer <paroga@paroga.com>
-// All rights reserved.
-// 
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-// 
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat <opensource@google.com>
-
-#ifndef TCMALLOC_INTERNAL_SPINLOCK_H__
-#define TCMALLOC_INTERNAL_SPINLOCK_H__
-
-#include <wtf/Atomics.h>
-#if OS(UNIX)
-#include <sched.h>
-#endif
-
-#if ENABLE(COMPARE_AND_SWAP)
-
-static void TCMalloc_SlowLock(unsigned* lockword);
-
-// The following is a struct so that it can be initialized at compile time
-struct TCMalloc_SpinLock {
-    void Lock() {
-      if (!WTF::weakCompareAndSwap(&lockword_, 0, 1))
-        TCMalloc_SlowLock(&lockword_);
-      WTF::memoryBarrierAfterLock();
-    }
-
-    void Unlock() {
-      WTF::memoryBarrierBeforeUnlock();
-      lockword_ = 0;
-    }
-
-    // Report if we think the lock can be held by this thread.
-    // When the lock is truly held by the invoking thread
-    // we will always return true.
-    // Indended to be used as CHECK(lock.IsHeld());
-    bool IsHeld() const {
-        return lockword_ != 0;
-    }
-
-    void Init() { lockword_ = 0; }
-    void Finalize() { }
-
-    unsigned lockword_;
-};
-
-#define SPINLOCK_INITIALIZER { 0 }
-
-static void TCMalloc_SlowLock(unsigned* lockword) {
-  do {
-#if OS(WINDOWS)
-    Sleep(0);
-#else
-    sched_yield();
-#endif
-  } while (!WTF::weakCompareAndSwap(lockword, 0, 1));
-}
-
-#else
-
-#include <pthread.h>
-
-// Portable version
-struct TCMalloc_SpinLock {
-  pthread_mutex_t private_lock_;
-
-  inline void Init() {
-    if (pthread_mutex_init(&private_lock_, NULL) != 0) CRASH();
-  }
-  inline void Finalize() {
-    if (pthread_mutex_destroy(&private_lock_) != 0) CRASH();
-  }
-  inline void Lock() {
-    if (pthread_mutex_lock(&private_lock_) != 0) CRASH();
-  }
-  inline void Unlock() {
-    if (pthread_mutex_unlock(&private_lock_) != 0) CRASH();
-  }
-  bool IsHeld() {
-    if (pthread_mutex_trylock(&private_lock_))
-      return true;
-
-    Unlock();
-    return false;
-  }
-};
-
-#define SPINLOCK_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
-
-#endif
-
-// Corresponding locker object that arranges to acquire a spinlock for
-// the duration of a C++ scope.
-class TCMalloc_SpinLockHolder {
- private:
-  TCMalloc_SpinLock* lock_;
- public:
-  inline explicit TCMalloc_SpinLockHolder(TCMalloc_SpinLock* l)
-    : lock_(l) { l->Lock(); }
-  inline ~TCMalloc_SpinLockHolder() { lock_->Unlock(); }
-};
-
-// Short-hands for convenient use by tcmalloc.cc
-typedef TCMalloc_SpinLock SpinLock;
-typedef TCMalloc_SpinLockHolder SpinLockHolder;
-
-#endif  // TCMALLOC_INTERNAL_SPINLOCK_H__
index 06290c2..19639ca 100644 (file)
@@ -33,7 +33,7 @@
 #include <wtf/unicode/UTF8.h>
 
 #if USE(WEB_THREAD)
-#include "TCSpinLock.h"
+#include "SpinLock.h"
 #endif
 
 namespace WTF {
@@ -47,7 +47,7 @@ static_assert(sizeof(AtomicString) == sizeof(String), "AtomicString and String m
 class AtomicStringTableLocker : public SpinLockHolder {
     WTF_MAKE_NONCOPYABLE(AtomicStringTableLocker);
 
-    static SpinLock s_stringTableLock;
+    static StaticSpinLock s_stringTableLock;
 public:
     AtomicStringTableLocker()
         : SpinLockHolder(&s_stringTableLock)
@@ -55,7 +55,7 @@ public:
     }
 };
 
-SpinLock AtomicStringTableLocker::s_stringTableLock = SPINLOCK_INITIALIZER;
+StaticSpinLock AtomicStringTableLocker::s_stringTableLock;
 
 #else
 
index 16af2a5..520cbd7 100644 (file)
@@ -1,3 +1,17 @@
+2015-03-13  Mark Lam  <mark.lam@apple.com>
+
+        Replace TCSpinLock with a new WTF::SpinLock based on WTF::Atomic.
+        <https://webkit.org/b/142674>
+
+        Reviewed by Filip Pizlo.
+
+        No new tests because there is no new functionality. This is a refactoring effort.
+
+        * bindings/objc/WebScriptObject.mm:
+        * platform/ios/wak/WAKWindow.mm:
+        (-[WAKWindow initWithLayer:]):
+        (-[WAKWindow initWithFrame:]):
+
 2015-03-13  Doug Russell  <d_russell@apple.com>
 
         AX: Provide API for assistive tech to ignore DOM key event handlers
index b31e3eb..5d9d8f5 100644 (file)
@@ -48,7 +48,7 @@
 #import <runtime/JSLock.h>
 #import <runtime/Completion.h>
 #import <runtime/Completion.h>
-#import <wtf/TCSpinLock.h>
+#import <wtf/SpinLock.h>
 #import <wtf/Threading.h>
 #import <wtf/spi/cocoa/NSMapTableSPI.h>
 #import <wtf/text/WTFString.h>
@@ -72,7 +72,7 @@ using JSC::makeSource;
 namespace WebCore {
 
 static NSMapTable* JSWrapperCache;
-static SpinLock spinLock = SPINLOCK_INITIALIZER;
+static StaticSpinLock spinLock;
 
 NSObject* getJSWrapper(JSObject* impl)
 {
index 0e1ce78..b4b588b 100644 (file)
@@ -36,7 +36,7 @@
 #import "WKContentObservation.h"
 #import "WKViewPrivate.h"
 #import <QuartzCore/QuartzCore.h>
-#import <wtf/TCSpinLock.h>
+#import <wtf/SpinLock.h>
 
 WEBCORE_EXPORT NSString * const WAKWindowScreenScaleDidChangeNotification = @"WAKWindowScreenScaleDidChangeNotification";
 WEBCORE_EXPORT NSString * const WAKWindowVisibilityDidChangeNotification = @"WAKWindowVisibilityDidChangeNotification";
@@ -77,7 +77,6 @@ static id<OrientationProvider> gOrientationProvider;
 
     _frozenVisibleRect = CGRectNull;
 
-    _exposedScrollViewRectLock = SPINLOCK_INITIALIZER;
     _exposedScrollViewRect = CGRectNull;
 
     return self;
@@ -93,7 +92,6 @@ static id<OrientationProvider> gOrientationProvider;
     _frame = frame;
     _screenScale = wkGetScreenScaleFactor();
 
-    _exposedScrollViewRectLock = SPINLOCK_INITIALIZER;
     _exposedScrollViewRect = CGRectNull;
 
     return self;
index d6c773a..e5f0496 100644 (file)
@@ -1,3 +1,17 @@
+2015-03-13  Mark Lam  <mark.lam@apple.com>
+
+        Replace TCSpinLock with a new WTF::SpinLock based on WTF::Atomic.
+        <https://webkit.org/b/142674>
+
+        Reviewed by Filip Pizlo.
+
+        * WebProcess/WebPage/EventDispatcher.cpp:
+        (WebKit::EventDispatcher::EventDispatcher):
+        * WebProcess/WebPage/EventDispatcher.h:
+        * WebProcess/WebPage/ViewUpdateDispatcher.cpp:
+        (WebKit::ViewUpdateDispatcher::ViewUpdateDispatcher):
+        * WebProcess/WebPage/ViewUpdateDispatcher.h:
+
 2015-03-10  Conrad Shultz  <conrad_shultz@apple.com>
 
         Allow clients to selectively disable plug-ins
index 9da6200..87cb5cc 100644 (file)
@@ -54,9 +54,6 @@ PassRefPtr<EventDispatcher> EventDispatcher::create()
 EventDispatcher::EventDispatcher()
     : m_queue(WorkQueue::create("com.apple.WebKit.EventDispatcher", WorkQueue::Type::Serial, WorkQueue::QOS::UserInteractive))
     , m_recentWheelEventDeltaTracker(std::make_unique<WheelEventDeltaTracker>())
-#if ENABLE(IOS_TOUCH_EVENTS)
-    , m_touchEventsLock(SPINLOCK_INITIALIZER)
-#endif
 {
 }
 
index ac9aee1..a60d400 100644 (file)
@@ -34,7 +34,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/RefPtr.h>
-#include <wtf/TCSpinLock.h>
+#include <wtf/SpinLock.h>
 #include <wtf/ThreadingPrimitives.h>
 
 namespace WebCore {
index 7915814..57f4a76 100644 (file)
@@ -42,7 +42,6 @@ Ref<ViewUpdateDispatcher> ViewUpdateDispatcher::create()
 
 ViewUpdateDispatcher::ViewUpdateDispatcher()
     : m_queue(WorkQueue::create("com.apple.WebKit.ViewUpdateDispatcher"))
-    , m_dataMutex(SPINLOCK_INITIALIZER)
 {
 }
 
index f240551..681704d 100644 (file)
@@ -31,7 +31,7 @@
 #include "VisibleContentRectUpdateInfo.h"
 #include <wtf/HashMap.h>
 #include <wtf/Ref.h>
-#include <wtf/TCSpinLock.h>
+#include <wtf/SpinLock.h>
 
 namespace WebKit {