Title: [161879] trunk/Source/WTF
Revision
161879
Author
[email protected]
Date
2014-01-13 08:38:44 -0800 (Mon, 13 Jan 2014)

Log Message

Remove AtomicallyInitializedStatic
https://bugs.webkit.org/show_bug.cgi?id=126864

Reviewed by Andreas Kling.

Remove the lockAtomicallyInitializedStaticMutex and unlockAtomicallyInitializedStaticMutex functions
everywhere except on Mac (where they unfortunately were used by Safari).

On Mac, add them to a separate file which will hold functions and symbols that we would like
to remove but that are used by Safari. Reimplement them in terms of std::call_once and std::mutex.

* WTF.xcodeproj/project.pbxproj:
* wtf/Threading.h:
* wtf/ThreadingPthreads.cpp:
(WTF::initializeThreading):
* wtf/ThreadingWin.cpp:
(WTF::initializeThreading):
* wtf/mac/DeprecatedSymbolsUsedBySafari.mm: Added.
(WTF::atomicallyInitializedStaticMutex):
(WTF::lockAtomicallyInitializedStaticMutex):
(WTF::unlockAtomicallyInitializedStaticMutex):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (161878 => 161879)


--- trunk/Source/WTF/ChangeLog	2014-01-13 16:15:46 UTC (rev 161878)
+++ trunk/Source/WTF/ChangeLog	2014-01-13 16:38:44 UTC (rev 161879)
@@ -1,3 +1,27 @@
+2014-01-13  Anders Carlsson  <[email protected]>
+
+        Remove AtomicallyInitializedStatic
+        https://bugs.webkit.org/show_bug.cgi?id=126864
+
+        Reviewed by Andreas Kling.
+
+        Remove the lockAtomicallyInitializedStaticMutex and unlockAtomicallyInitializedStaticMutex functions
+        everywhere except on Mac (where they unfortunately were used by Safari).
+        
+        On Mac, add them to a separate file which will hold functions and symbols that we would like
+        to remove but that are used by Safari. Reimplement them in terms of std::call_once and std::mutex.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/Threading.h:
+        * wtf/ThreadingPthreads.cpp:
+        (WTF::initializeThreading):
+        * wtf/ThreadingWin.cpp:
+        (WTF::initializeThreading):
+        * wtf/mac/DeprecatedSymbolsUsedBySafari.mm: Added.
+        (WTF::atomicallyInitializedStaticMutex):
+        (WTF::lockAtomicallyInitializedStaticMutex):
+        (WTF::unlockAtomicallyInitializedStaticMutex):
+
 2014-01-13  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r161855.

Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (161878 => 161879)


--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2014-01-13 16:15:46 UTC (rev 161878)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2014-01-13 16:38:44 UTC (rev 161879)
@@ -56,6 +56,7 @@
 		1A233C7D17DAA6E300A93ACF /* MallocPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A233C7C17DAA6E300A93ACF /* MallocPtr.h */; };
 		1A6BB769162F300500DD16DB /* StreamBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6BB768162F300500DD16DB /* StreamBuffer.h */; };
 		1A6EB1E0187D0BD30030126F /* StringView.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6EB1DF187D0BD30030126F /* StringView.h */; };
+		1ACADD841884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1ACADD821884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm */; };
 		1FA47C8A152502DA00568D1B /* WebCoreThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FA47C88152502DA00568D1B /* WebCoreThread.cpp */; };
 		1FA47C8B152502DA00568D1B /* WebCoreThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA47C89152502DA00568D1B /* WebCoreThread.h */; };
 		26147B0A15DDCCDC00DDB907 /* IntegerToStringConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */; };
@@ -324,6 +325,7 @@
 		1A3F6BE6174ADA2100B2EEA7 /* NeverDestroyed.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NeverDestroyed.h; sourceTree = "<group>"; };
 		1A6BB768162F300500DD16DB /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = "<group>"; };
 		1A6EB1DF187D0BD30030126F /* StringView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringView.h; sourceTree = "<group>"; };
+		1ACADD821884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeprecatedSymbolsUsedBySafari.mm; sourceTree = "<group>"; };
 		1FA47C88152502DA00568D1B /* WebCoreThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreThread.cpp; sourceTree = "<group>"; };
 		1FA47C89152502DA00568D1B /* WebCoreThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreThread.h; sourceTree = "<group>"; };
 		26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntegerToStringConversion.h; sourceTree = "<group>"; };
@@ -873,6 +875,7 @@
 			isa = PBXGroup;
 			children = (
 				A8A472C5151A825A004123FF /* MainThreadMac.mm */,
+				1ACADD821884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -1272,6 +1275,7 @@
 				A8A473B7151A825B004123FF /* strtod.cc in Sources */,
 				A8A47431151A825B004123FF /* TCSystemAlloc.cpp in Sources */,
 				A8A47448151A825B004123FF /* ThreadIdentifierDataPthreads.cpp in Sources */,
+				1ACADD841884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm in Sources */,
 				A8A4744A151A825B004123FF /* Threading.cpp in Sources */,
 				A8A4744E151A825B004123FF /* ThreadingPthreads.cpp in Sources */,
 				A8A47469151A825B004123FF /* UTF8.cpp in Sources */,

Modified: trunk/Source/WTF/wtf/Threading.h (161878 => 161879)


--- trunk/Source/WTF/wtf/Threading.h	2014-01-13 16:15:46 UTC (rev 161878)
+++ trunk/Source/WTF/wtf/Threading.h	2014-01-13 16:38:44 UTC (rev 161879)
@@ -69,12 +69,6 @@
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/ThreadingPrimitives.h>
 
-// For portability, we do not use thread-safe statics natively supported by some compilers (e.g. gcc).
-#define AtomicallyInitializedStatic(T, name) \
-    WTF::lockAtomicallyInitializedStaticMutex(); \
-    static T name; \
-    WTF::unlockAtomicallyInitializedStaticMutex();
-
 namespace WTF {
 
 typedef uint32_t ThreadIdentifier;
@@ -100,9 +94,6 @@
 WTF_EXPORT_PRIVATE int waitForThreadCompletion(ThreadIdentifier);
 WTF_EXPORT_PRIVATE void detachThread(ThreadIdentifier);
 
-WTF_EXPORT_PRIVATE void lockAtomicallyInitializedStaticMutex();
-WTF_EXPORT_PRIVATE void unlockAtomicallyInitializedStaticMutex();
-
 } // namespace WTF
 
 using WTF::ThreadIdentifier;

Modified: trunk/Source/WTF/wtf/ThreadingPthreads.cpp (161878 => 161879)


--- trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2014-01-13 16:15:46 UTC (rev 161878)
+++ trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2014-01-13 16:38:44 UTC (rev 161879)
@@ -98,8 +98,6 @@
 
 typedef HashMap<ThreadIdentifier, std::unique_ptr<PthreadState>> ThreadMap;
 
-static Mutex* atomicallyInitializedStaticMutex;
-
 void unsafeThreadWasDetached(ThreadIdentifier);
 void threadDidExit(ThreadIdentifier);
 void threadWasJoined(ThreadIdentifier);
@@ -112,14 +110,17 @@
 
 void initializeThreading()
 {
-    if (atomicallyInitializedStaticMutex)
+    static bool isInitialized;
+
+    if (isInitialized)
         return;
 
+    isInitialized = true;
+
     WTF::double_conversion::initialize();
     // StringImpl::empty() does not construct its static string in a threadsafe fashion,
     // so ensure it has been initialized from here.
     StringImpl::empty();
-    atomicallyInitializedStaticMutex = new Mutex;
     threadMapMutex();
     initializeRandomNumberGenerator();
     ThreadIdentifierData::initializeOnce();
@@ -129,17 +130,6 @@
     initializeDates();
 }
 
-void lockAtomicallyInitializedStaticMutex()
-{
-    ASSERT(atomicallyInitializedStaticMutex);
-    atomicallyInitializedStaticMutex->lock();
-}
-
-void unlockAtomicallyInitializedStaticMutex()
-{
-    atomicallyInitializedStaticMutex->unlock();
-}
-
 static ThreadMap& threadMap()
 {
     DEFINE_STATIC_LOCAL(ThreadMap, map, ());

Modified: trunk/Source/WTF/wtf/ThreadingWin.cpp (161878 => 161879)


--- trunk/Source/WTF/wtf/ThreadingWin.cpp	2014-01-13 16:15:46 UTC (rev 161878)
+++ trunk/Source/WTF/wtf/ThreadingWin.cpp	2014-01-13 16:38:44 UTC (rev 161879)
@@ -148,19 +148,6 @@
 #endif
 }
 
-static Mutex* atomicallyInitializedStaticMutex;
-
-void lockAtomicallyInitializedStaticMutex()
-{
-    ASSERT(atomicallyInitializedStaticMutex);
-    atomicallyInitializedStaticMutex->lock();
-}
-
-void unlockAtomicallyInitializedStaticMutex()
-{
-    atomicallyInitializedStaticMutex->unlock();
-}
-
 static Mutex& threadMapMutex()
 {
     static Mutex mutex;
@@ -169,9 +156,13 @@
 
 void initializeThreading()
 {
-    if (atomicallyInitializedStaticMutex)
+    static bool isInitialized;
+    
+    if (isInitialized)
         return;
 
+    isInitialized = true;
+
     WTF::double_conversion::initialize();
     // StringImpl::empty() does not construct its static string in a threadsafe fashion,
     // so ensure it has been initialized from here.

Added: trunk/Source/WTF/wtf/mac/DeprecatedSymbolsUsedBySafari.mm (0 => 161879)


--- trunk/Source/WTF/wtf/mac/DeprecatedSymbolsUsedBySafari.mm	                        (rev 0)
+++ trunk/Source/WTF/wtf/mac/DeprecatedSymbolsUsedBySafari.mm	2014-01-13 16:38:44 UTC (rev 161879)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2014 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. AND ITS 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 APPLE INC. OR ITS 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.
+ */
+
+#include "config.h"
+
+#include "StdLibExtras.h"
+#include <mutex>
+
+// This file contains deprecated symbols that the last released version of Safari uses.
+// Once Safari stops using them, we should remove them.
+
+namespace WTF {
+
+WTF_EXPORT void lockAtomicallyInitializedStaticMutex();
+WTF_EXPORT void unlockAtomicallyInitializedStaticMutex();
+
+static std::mutex& atomicallyInitializedStaticMutex()
+{
+    static std::once_flag onceFlag;
+    static std::mutex* mutex;
+    std::call_once(onceFlag, []{
+        mutex = std::make_unique<std::mutex>().release();
+    });
+
+    return *mutex;
+}
+
+void lockAtomicallyInitializedStaticMutex()
+{
+    atomicallyInitializedStaticMutex().lock();
+}
+
+void unlockAtomicallyInitializedStaticMutex()
+{
+    atomicallyInitializedStaticMutex().unlock();
+}
+
+} // namespace WTF
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to