Use StaticLock instead of NeverDestroyed<Lock>
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Dec 2017 01:31:10 +0000 (01:31 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Dec 2017 01:31:10 +0000 (01:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180507

Reviewed by Saam Barati.

Source/WebCore:

StaticLock can be used instead of using NeverDestroyed<Lock>.

No behavior change.

* Modules/webdatabase/Database.cpp:
(WebCore::Database::performOpenAndVerify):
* Modules/webdatabase/DatabaseTracker.cpp:
(WebCore::DatabaseTracker::openDatabaseMutex):
(WebCore::DatabaseTracker::emptyDatabaseFilesRemovalTaskWillBeScheduled):
(WebCore::DatabaseTracker::emptyDatabaseFilesRemovalTaskDidFinish):
(WebCore::DatabaseTracker::scheduleNotifyDatabaseChanged):
(WebCore::DatabaseTracker::scheduleForNotification):
(WebCore::DatabaseTracker::notifyDatabasesChanged):
(WebCore::notificationMutex): Deleted.
* Modules/webdatabase/DatabaseTracker.h:
* platform/URL.cpp:
(WebCore::registerDefaultPortForProtocolForTesting):
(WebCore::clearDefaultPortForProtocolMapForTesting):
(WebCore::defaultPortForProtocol):
(WebCore::defaultPortForProtocolMapForTestingLock): Deleted.
* platform/graphics/MediaPlayer.cpp:
(WebCore::buildMediaEnginesVector):
(WebCore::installedMediaEngines):
(WebCore::MediaPlayer::resetMediaEngines):
(WebCore::mediaEngineVectorLock): Deleted.
* platform/ios/QuickLook.mm:
(WebCore::removeQLPreviewConverterForURL):
(WebCore::addQLPreviewConverterWithFileForURL):
(WebCore::qlPreviewConverterDictionaryMutex): Deleted.
* platform/ios/WebSQLiteDatabaseTrackerClient.mm:
(+[WebDatabaseTransactionBackgroundTaskController startBackgroundTask]):
(+[WebDatabaseTransactionBackgroundTaskController endBackgroundTask]):
(transactionBackgroundTaskIdentifierLock): Deleted.
* platform/network/curl/CurlContext.cpp:
(WebCore::CurlShareHandle::lockCallback):
(WebCore::CurlShareHandle::unlockCallback):
(WebCore::CurlShareHandle::mutexFor):
* platform/network/curl/CurlContext.h:

Source/WebKitLegacy/ios:

* WebCoreSupport/WebFixedPositionContent.mm:
(-[WebFixedPositionContent scrollOrZoomChanged:]):
(-[WebFixedPositionContent overflowScrollPositionForLayer:changedTo:]):
(-[WebFixedPositionContent setViewportConstrainedLayers:stickyContainerMap:]):
(-[WebFixedPositionContent hasFixedOrStickyPositionLayers]):
(WebFixedPositionContentDataLock): Deleted.

Source/WebKitLegacy/win:

* WebLocalizableStrings.cpp:
(findCachedString):
(cacheString):
(mainBundleLocStrings): Deleted.
(frameworkLocStringsMutex): Deleted.

Tools:

* DumpRenderTree/JavaScriptThreading.cpp:
(javaScriptThreads):
(runJavaScriptThread):
(startJavaScriptThreads):
(stopJavaScriptThreads):
(javaScriptThreadsMutex): Deleted.

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/webdatabase/Database.cpp
Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp
Source/WebCore/Modules/webdatabase/DatabaseTracker.h
Source/WebCore/platform/URL.cpp
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/ios/QuickLook.mm
Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm
Source/WebCore/platform/network/curl/CurlContext.cpp
Source/WebCore/platform/network/curl/CurlContext.h
Source/WebKitLegacy/ios/ChangeLog
Source/WebKitLegacy/ios/WebCoreSupport/WebFixedPositionContent.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebLocalizableStrings.cpp
Tools/ChangeLog
Tools/DumpRenderTree/JavaScriptThreading.cpp

index 3ac2d6b..99458f4 100644 (file)
@@ -1,3 +1,49 @@
+2017-12-07  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Use StaticLock instead of NeverDestroyed<Lock>
+        https://bugs.webkit.org/show_bug.cgi?id=180507
+
+        Reviewed by Saam Barati.
+
+        StaticLock can be used instead of using NeverDestroyed<Lock>.
+
+        No behavior change.
+
+        * Modules/webdatabase/Database.cpp:
+        (WebCore::Database::performOpenAndVerify):
+        * Modules/webdatabase/DatabaseTracker.cpp:
+        (WebCore::DatabaseTracker::openDatabaseMutex):
+        (WebCore::DatabaseTracker::emptyDatabaseFilesRemovalTaskWillBeScheduled):
+        (WebCore::DatabaseTracker::emptyDatabaseFilesRemovalTaskDidFinish):
+        (WebCore::DatabaseTracker::scheduleNotifyDatabaseChanged):
+        (WebCore::DatabaseTracker::scheduleForNotification):
+        (WebCore::DatabaseTracker::notifyDatabasesChanged):
+        (WebCore::notificationMutex): Deleted.
+        * Modules/webdatabase/DatabaseTracker.h:
+        * platform/URL.cpp:
+        (WebCore::registerDefaultPortForProtocolForTesting):
+        (WebCore::clearDefaultPortForProtocolMapForTesting):
+        (WebCore::defaultPortForProtocol):
+        (WebCore::defaultPortForProtocolMapForTestingLock): Deleted.
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::buildMediaEnginesVector):
+        (WebCore::installedMediaEngines):
+        (WebCore::MediaPlayer::resetMediaEngines):
+        (WebCore::mediaEngineVectorLock): Deleted.
+        * platform/ios/QuickLook.mm:
+        (WebCore::removeQLPreviewConverterForURL):
+        (WebCore::addQLPreviewConverterWithFileForURL):
+        (WebCore::qlPreviewConverterDictionaryMutex): Deleted.
+        * platform/ios/WebSQLiteDatabaseTrackerClient.mm:
+        (+[WebDatabaseTransactionBackgroundTaskController startBackgroundTask]):
+        (+[WebDatabaseTransactionBackgroundTaskController endBackgroundTask]):
+        (transactionBackgroundTaskIdentifierLock): Deleted.
+        * platform/network/curl/CurlContext.cpp:
+        (WebCore::CurlShareHandle::lockCallback):
+        (WebCore::CurlShareHandle::unlockCallback):
+        (WebCore::CurlShareHandle::mutexFor):
+        * platform/network/curl/CurlContext.h:
+
 2017-12-07  Brady Eidson  <beidson@apple.com>
 
         Read registrations in from disk.
index bdecfa0..dd75a3d 100644 (file)
@@ -341,7 +341,7 @@ ExceptionOr<void> Database::performOpenAndVerify(bool shouldSetVersionInNewDatab
 #if PLATFORM(IOS)
     {
         // Make sure we wait till the background removal of the empty database files finished before trying to open any database.
-        LockHolder locker(DatabaseTracker::openDatabaseMutex());
+        auto locker = holdLock(DatabaseTracker::openDatabaseMutex());
     }
 #endif
 
index fea1be5..4279038 100644 (file)
@@ -1275,22 +1275,22 @@ bool DatabaseTracker::deleteDatabaseFileIfEmpty(const String& path)
     return SQLiteFileSystem::deleteDatabaseFile(path);
 }
 
-Lock& DatabaseTracker::openDatabaseMutex()
+static StaticLock openDatabaseLock;
+StaticLock& DatabaseTracker::openDatabaseMutex()
 {
-    static NeverDestroyed<Lock> mutex;
-    return mutex;
+    return openDatabaseLock;
 }
 
 void DatabaseTracker::emptyDatabaseFilesRemovalTaskWillBeScheduled()
 {
     // Lock the database from opening any database until we are done with scanning the file system for
     // zero byte database files to remove.
-    openDatabaseMutex().lock();
+    openDatabaseLock.lock();
 }
 
 void DatabaseTracker::emptyDatabaseFilesRemovalTaskDidFinish()
 {
-    openDatabaseMutex().unlock();
+    openDatabaseLock.unlock();
 }
 
 #endif
@@ -1300,11 +1300,7 @@ void DatabaseTracker::setClient(DatabaseManagerClient* client)
     m_client = client;
 }
 
-static Lock& notificationMutex()
-{
-    static NeverDestroyed<Lock> mutex;
-    return mutex;
-}
+static StaticLock notificationLock;
 
 using NotificationQueue = Vector<std::pair<SecurityOriginData, String>>;
 
@@ -1316,7 +1312,7 @@ static NotificationQueue& notificationQueue()
 
 void DatabaseTracker::scheduleNotifyDatabaseChanged(const SecurityOriginData& origin, const String& name)
 {
-    LockHolder locker(notificationMutex());
+    auto locker = holdLock(notificationLock);
     notificationQueue().append(std::make_pair(origin.isolatedCopy(), name.isolatedCopy()));
     scheduleForNotification();
 }
@@ -1325,7 +1321,7 @@ static bool notificationScheduled = false;
 
 void DatabaseTracker::scheduleForNotification()
 {
-    ASSERT(!notificationMutex().tryLock());
+    ASSERT(!notificationLock.tryLock());
 
     if (!notificationScheduled) {
         callOnMainThread([] {
@@ -1343,7 +1339,7 @@ void DatabaseTracker::notifyDatabasesChanged()
 
     NotificationQueue notifications;
     {
-        LockHolder locker(notificationMutex());
+        auto locker = holdLock(notificationLock);
         notifications.swap(notificationQueue());
         notificationScheduled = false;
     }
index c76614f..d5802a1 100644 (file)
@@ -100,7 +100,7 @@ public:
     // MobileSafari will grab this mutex on the main thread before dispatching the task to 
     // clean up zero byte database files.  Any operations to open new database will have to
     // wait for that task to finish by waiting on this mutex.
-    static Lock& openDatabaseMutex();
+    static StaticLock& openDatabaseMutex();
     
     WEBCORE_EXPORT static void emptyDatabaseFilesRemovalTaskWillBeScheduled();
     WEBCORE_EXPORT static void emptyDatabaseFilesRemovalTaskDidFinish();
index 2f355a9..dc19a14 100644 (file)
@@ -275,11 +275,7 @@ static void assertProtocolIsGood(StringView protocol)
 
 #endif
 
-static Lock& defaultPortForProtocolMapForTestingLock()
-{
-    static NeverDestroyed<Lock> lock;
-    return lock;
-}
+static StaticLock defaultPortForProtocolMapForTestingLock;
 
 using DefaultPortForProtocolMapForTesting = HashMap<String, uint16_t>;
 static DefaultPortForProtocolMapForTesting*& defaultPortForProtocolMapForTesting()
@@ -298,13 +294,13 @@ static DefaultPortForProtocolMapForTesting& ensureDefaultPortForProtocolMapForTe
 
 void registerDefaultPortForProtocolForTesting(uint16_t port, const String& protocol)
 {
-    LockHolder locker(defaultPortForProtocolMapForTestingLock());
+    auto locker = holdLock(defaultPortForProtocolMapForTestingLock);
     ensureDefaultPortForProtocolMapForTesting().add(protocol, port);
 }
 
 void clearDefaultPortForProtocolMapForTesting()
 {
-    LockHolder locker(defaultPortForProtocolMapForTestingLock());
+    auto locker = holdLock(defaultPortForProtocolMapForTestingLock);
     if (auto* map = defaultPortForProtocolMapForTesting())
         map->clear();
 }
@@ -312,7 +308,7 @@ void clearDefaultPortForProtocolMapForTesting()
 std::optional<uint16_t> defaultPortForProtocol(StringView protocol)
 {
     if (auto* overrideMap = defaultPortForProtocolMapForTesting()) {
-        LockHolder locker(defaultPortForProtocolMapForTestingLock());
+        auto locker = holdLock(defaultPortForProtocolMapForTestingLock);
         ASSERT(overrideMap); // No need to null check again here since overrideMap cannot become null after being non-null.
         auto iterator = overrideMap->find(protocol.toStringWithoutCopying());
         if (iterator != overrideMap->end())
index 35c5a5e..4a473af 100644 (file)
@@ -210,11 +210,7 @@ struct MediaPlayerFactory {
 
 static void addMediaEngine(CreateMediaEnginePlayer&&, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineOriginsInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForOrigins, MediaEngineSupportsKeySystem);
 
-static Lock& mediaEngineVectorLock()
-{
-    static NeverDestroyed<Lock> lock;
-    return lock;
-}
+static StaticLock mediaEngineVectorLock;
 
 static bool& haveMediaEnginesVector()
 {
@@ -230,7 +226,7 @@ static Vector<MediaPlayerFactory>& mutableInstalledMediaEnginesVector()
 
 static void buildMediaEnginesVector()
 {
-    ASSERT(mediaEngineVectorLock().isLocked());
+    ASSERT(mediaEngineVectorLock.isLocked());
 
 #if USE(AVFOUNDATION)
     if (DeprecatedGlobalSettings::isAVFoundationEnabled()) {
@@ -276,7 +272,7 @@ static void buildMediaEnginesVector()
 static const Vector<MediaPlayerFactory>& installedMediaEngines()
 {
     {
-        LockHolder lock(mediaEngineVectorLock());
+        auto locker = holdLock(mediaEngineVectorLock);
         if (!haveMediaEnginesVector())
             buildMediaEnginesVector();
     }
@@ -1388,7 +1384,7 @@ Vector<RefPtr<PlatformTextTrack>> MediaPlayer::outOfBandTrackSources()
 
 void MediaPlayer::resetMediaEngines()
 {
-    LockHolder lock(mediaEngineVectorLock());
+    auto locker = holdLock(mediaEngineVectorLock);
 
     mutableInstalledMediaEnginesVector().clear();
     haveMediaEnginesVector() = false;
index d3df8ee..f3b0df6 100644 (file)
@@ -46,11 +46,7 @@ NSSet *QLPreviewGetSupportedMIMETypesSet()
     return set;
 }
 
-static Lock& qlPreviewConverterDictionaryMutex()
-{
-    static NeverDestroyed<Lock> mutex;
-    return mutex;
-}
+static StaticLock qlPreviewConverterDictionaryLock;
 
 static NSMutableDictionary *QLPreviewConverterDictionary()
 {
@@ -66,7 +62,7 @@ static NSMutableDictionary *QLContentDictionary()
 
 void removeQLPreviewConverterForURL(NSURL *url)
 {
-    LockHolder lock(qlPreviewConverterDictionaryMutex());
+    auto locker = holdLock(qlPreviewConverterDictionaryLock);
     [QLPreviewConverterDictionary() removeObjectForKey:url];
     [QLContentDictionary() removeObjectForKey:url];
 }
@@ -75,7 +71,7 @@ static void addQLPreviewConverterWithFileForURL(NSURL *url, id converter, NSStri
 {
     ASSERT(url);
     ASSERT(converter);
-    LockHolder lock(qlPreviewConverterDictionaryMutex());
+    auto locker = holdLock(qlPreviewConverterDictionaryLock);
     [QLPreviewConverterDictionary() setObject:converter forKey:url];
     [QLContentDictionary() setObject:(fileName ? fileName : @"") forKey:url];
 }
index 4bd3fa1..96fcbf1 100644 (file)
@@ -84,11 +84,7 @@ void WebSQLiteDatabaseTrackerClient::hysteresisUpdated(PAL::HysteresisState stat
 
 }
 
-static Lock& transactionBackgroundTaskIdentifierLock()
-{
-    static NeverDestroyed<Lock> mutex;
-    return mutex;
-}
+static StaticLock transactionBackgroundTaskIdentifierLock;
 
 static NSUInteger transactionBackgroundTaskIdentifier;
 
@@ -111,7 +107,7 @@ static NSUInteger getTransactionBackgroundTaskIdentifier()
 
 + (void)startBackgroundTask
 {
-    LockHolder lock(transactionBackgroundTaskIdentifierLock());
+    auto locker = holdLock(transactionBackgroundTaskIdentifierLock);
 
     // If there's already an existing background task going on, there's no need to start a new one.
     WebBackgroundTaskController *backgroundTaskController = [WebBackgroundTaskController sharedController];
@@ -126,7 +122,7 @@ static NSUInteger getTransactionBackgroundTaskIdentifier()
 
 + (void)endBackgroundTask
 {
-    LockHolder lock(transactionBackgroundTaskIdentifierLock());
+    auto locker = holdLock(transactionBackgroundTaskIdentifierLock);
 
     // It is possible that we were unable to start the background task when the first transaction began.
     // Don't try to end the task in that case.
index dea3602..8bcd08d 100644 (file)
@@ -178,29 +178,29 @@ CurlShareHandle::~CurlShareHandle()
 
 void CurlShareHandle::lockCallback(CURL*, curl_lock_data data, curl_lock_access, void*)
 {
-    if (Lock* mutex = mutexFor(data))
+    if (auto* mutex = mutexFor(data))
         mutex->lock();
 }
 
 void CurlShareHandle::unlockCallback(CURL*, curl_lock_data data, void*)
 {
-    if (Lock* mutex = mutexFor(data))
+    if (auto* mutex = mutexFor(data))
         mutex->unlock();
 }
 
-Lock* CurlShareHandle::mutexFor(curl_lock_data data)
+StaticLock* CurlShareHandle::mutexFor(curl_lock_data data)
 {
-    static NeverDestroyed<Lock> cookieMutex;
-    static NeverDestroyed<Lock> dnsMutex;
-    static NeverDestroyed<Lock> shareMutex;
+    static StaticLock cookieMutex;
+    static StaticLock dnsMutex;
+    static StaticLock shareMutex;
 
     switch (data) {
     case CURL_LOCK_DATA_COOKIE:
-        return &cookieMutex.get();
+        return &cookieMutex;
     case CURL_LOCK_DATA_DNS:
-        return &dnsMutex.get();
+        return &dnsMutex;
     case CURL_LOCK_DATA_SHARE:
-        return &shareMutex.get();
+        return &shareMutex;
     default:
         ASSERT_NOT_REACHED();
         return nullptr;
index 92d3bac..9684653 100644 (file)
@@ -83,7 +83,7 @@ public:
 private:
     static void lockCallback(CURL*, curl_lock_data, curl_lock_access, void*);
     static void unlockCallback(CURL*, curl_lock_data, void*);
-    static Lock* mutexFor(curl_lock_data);
+    static StaticLock* mutexFor(curl_lock_data);
 
     CURLSH* m_shareHandle { nullptr };
 };
index 234ff64..01b1f30 100644 (file)
@@ -1,3 +1,17 @@
+2017-12-07  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Use StaticLock instead of NeverDestroyed<Lock>
+        https://bugs.webkit.org/show_bug.cgi?id=180507
+
+        Reviewed by Saam Barati.
+
+        * WebCoreSupport/WebFixedPositionContent.mm:
+        (-[WebFixedPositionContent scrollOrZoomChanged:]):
+        (-[WebFixedPositionContent overflowScrollPositionForLayer:changedTo:]):
+        (-[WebFixedPositionContent setViewportConstrainedLayers:stickyContainerMap:]):
+        (-[WebFixedPositionContent hasFixedOrStickyPositionLayers]):
+        (WebFixedPositionContentDataLock): Deleted.
+
 2017-11-11  Megan Gardner  <megan_gardner@apple.com>
 
         Fix a FIXMEs in WebFrameIOS
index f5d3592..f27dba7 100644 (file)
 using namespace WebCore;
 using namespace std;
 
-static Lock& WebFixedPositionContentDataLock()
-{
-    static NeverDestroyed<Lock> mutex;
-    return mutex;
-}
+static StaticLock webFixedPositionContentDataLock;
 
 struct ViewportConstrainedLayerData {
     ViewportConstrainedLayerData()
@@ -104,7 +100,7 @@ WebFixedPositionContentData::~WebFixedPositionContentData()
 
 - (void)scrollOrZoomChanged:(CGRect)positionedObjectsRect
 {
-    LockHolder lock(WebFixedPositionContentDataLock());
+    auto locker = holdLock(webFixedPositionContentDataLock);
 
     LayerInfoMap::const_iterator end = _private->m_viewportConstrainedLayers.end();
     for (LayerInfoMap::const_iterator it = _private->m_viewportConstrainedLayers.begin(); it != end; ++it) {
@@ -143,7 +139,7 @@ WebFixedPositionContentData::~WebFixedPositionContentData()
 
 - (void)overflowScrollPositionForLayer:(CALayer *)scrollLayer changedTo:(CGPoint)scrollPosition
 {
-    LockHolder lock(WebFixedPositionContentDataLock());
+    auto locker = holdLock(webFixedPositionContentDataLock);
 
     LayerInfoMap::const_iterator end = _private->m_viewportConstrainedLayers.end();
     for (LayerInfoMap::const_iterator it = _private->m_viewportConstrainedLayers.begin(); it != end; ++it) {
@@ -176,7 +172,7 @@ WebFixedPositionContentData::~WebFixedPositionContentData()
 
 - (void)setViewportConstrainedLayers:(WTF::HashMap<CALayer *, std::unique_ptr<WebCore::ViewportConstraints>>&)layerMap stickyContainerMap:(WTF::HashMap<CALayer*, CALayer*>&)stickyContainers
 {
-    LockHolder lock(WebFixedPositionContentDataLock());
+    auto locker = holdLock(webFixedPositionContentDataLock);
 
     _private->m_viewportConstrainedLayers.clear();
 
@@ -193,7 +189,7 @@ WebFixedPositionContentData::~WebFixedPositionContentData()
 
 - (BOOL)hasFixedOrStickyPositionLayers
 {
-    LockHolder lock(WebFixedPositionContentDataLock());
+    auto locker = holdLock(webFixedPositionContentDataLock);
     return !_private->m_viewportConstrainedLayers.isEmpty();
 }
 
index b07eafb..0f657af 100644 (file)
@@ -1,3 +1,16 @@
+2017-12-07  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Use StaticLock instead of NeverDestroyed<Lock>
+        https://bugs.webkit.org/show_bug.cgi?id=180507
+
+        Reviewed by Saam Barati.
+
+        * WebLocalizableStrings.cpp:
+        (findCachedString):
+        (cacheString):
+        (mainBundleLocStrings): Deleted.
+        (frameworkLocStringsMutex): Deleted.
+
 2017-12-05  Per Arne Vollan  <pvollan@apple.com>
 
         [Win] Scrollbars are sometimes not rendered in accelerated compositing mode.
index b757391..2e311ee 100644 (file)
@@ -45,11 +45,7 @@ WebLocalizableStringsBundle WebKitLocalizableStringsBundle = { "com.apple.WebKit
 
 typedef HashMap<String, LocalizedString*> LocalizedStringMap;
 
-static Lock& mainBundleLocStringsMutex()
-{
-    static NeverDestroyed<Lock> mutex;
-    return mutex;
-}
+static StaticLock mainBundleLocStringsLock;
 
 static LocalizedStringMap& mainBundleLocStrings()
 {
@@ -57,11 +53,7 @@ static LocalizedStringMap& mainBundleLocStrings()
     return map;
 }
 
-static Lock& frameworkLocStringsMutex()
-{
-    static NeverDestroyed<Lock> mutex;
-    return mutex;
-}
+static StaticLock frameworkLocStringsLock;
 
 static LocalizedStringMap frameworkLocStrings()
 {
@@ -176,12 +168,12 @@ static CFStringRef copyLocalizedStringFromBundle(WebLocalizableStringsBundle* st
 static LocalizedString* findCachedString(WebLocalizableStringsBundle* stringsBundle, const String& key)
 {
     if (!stringsBundle) {
-        LockHolder lock(mainBundleLocStringsMutex());
+        auto locker = holdLock(mainBundleLocStringsLock);
         return mainBundleLocStrings().get(key);
     }
 
     if (stringsBundle->bundle == WebKitLocalizableStringsBundle.bundle) {
-        LockHolder lock(frameworkLocStringsMutex());
+        auto locker = holdLock(frameworkLocStringsLock);
         return frameworkLocStrings().get(key);
     }
 
@@ -191,12 +183,12 @@ static LocalizedString* findCachedString(WebLocalizableStringsBundle* stringsBun
 static void cacheString(WebLocalizableStringsBundle* stringsBundle, const String& key, LocalizedString* value)
 {
     if (!stringsBundle) {
-        LockHolder lock(mainBundleLocStringsMutex());
+        auto locker = holdLock(mainBundleLocStringsLock);
         mainBundleLocStrings().set(key, value);
         return;
     }
 
-    LockHolder lock(frameworkLocStringsMutex());
+    auto locker = holdLock(frameworkLocStringsLock);
     frameworkLocStrings().set(key, value);
 }
 
index 0256ebf..4c99862 100644 (file)
@@ -1,3 +1,17 @@
+2017-12-07  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Use StaticLock instead of NeverDestroyed<Lock>
+        https://bugs.webkit.org/show_bug.cgi?id=180507
+
+        Reviewed by Saam Barati.
+
+        * DumpRenderTree/JavaScriptThreading.cpp:
+        (javaScriptThreads):
+        (runJavaScriptThread):
+        (startJavaScriptThreads):
+        (stopJavaScriptThreads):
+        (javaScriptThreadsMutex): Deleted.
+
 2017-12-07  Alex Christensen  <achristensen@webkit.org>
 
         Always synchronously continue with fragment navigations
index 53517bf..80a082b 100644 (file)
 static const size_t javaScriptThreadsCount = 4;
 static bool javaScriptThreadsShouldTerminate;
 static JSContextGroupRef javaScriptThreadsGroup;
-
-static Lock& javaScriptThreadsMutex()
-{
-    static NeverDestroyed<Lock> staticMutex;
-    return staticMutex;
-}
+static StaticLock javaScriptThreadsLock;
 
 typedef HashSet<RefPtr<Thread>> ThreadSet;
 static ThreadSet& javaScriptThreads()
 {
     static NeverDestroyed<ThreadSet> staticJavaScriptThreads;
-    ASSERT(!javaScriptThreadsMutex().tryLock());
+    ASSERT(!javaScriptThreadsLock.tryLock());
     return staticJavaScriptThreads;
 }
 
@@ -72,26 +67,26 @@ void runJavaScriptThread()
 
     JSGlobalContextRef ctx;
     {
-        LockHolder locker(javaScriptThreadsMutex());
+        auto locker = holdLock(javaScriptThreadsLock);
         ctx = JSGlobalContextCreateInGroup(javaScriptThreadsGroup, 0);
     }
 
     JSStringRef scriptRef;
     {
-        LockHolder locker(javaScriptThreadsMutex());
+        auto locker = holdLock(javaScriptThreadsLock);
         scriptRef = JSStringCreateWithUTF8CString(script);
     }
 
     while (true) {
         {
-            LockHolder locker(javaScriptThreadsMutex());
+            auto locker = holdLock(javaScriptThreadsLock);
             JSValueRef exception = 0;
             JSEvaluateScript(ctx, scriptRef, 0, 0, 1, &exception);
             ASSERT(!exception);
         }
 
         {
-            LockHolder locker(javaScriptThreadsMutex());
+            auto locker = holdLock(javaScriptThreadsLock);
             const size_t valuesCount = 1024;
             JSValueRef values[valuesCount];
             for (size_t i = 0; i < valuesCount; ++i)
@@ -99,7 +94,7 @@ void runJavaScriptThread()
         }
 
         {
-            LockHolder locker(javaScriptThreadsMutex());
+            auto locker = holdLock(javaScriptThreadsLock);
             if (javaScriptThreadsShouldTerminate)
                 break;
         }
@@ -108,7 +103,7 @@ void runJavaScriptThread()
         if (rand() % 5)
             continue;
 
-        LockHolder locker(javaScriptThreadsMutex());
+        auto locker = holdLock(javaScriptThreadsLock);
         Thread& thread = Thread::current();
         thread.detach();
         javaScriptThreads().remove(&thread);
@@ -116,7 +111,7 @@ void runJavaScriptThread()
         break;
     }
 
-    LockHolder locker(javaScriptThreadsMutex());
+    auto locker = holdLock(javaScriptThreadsLock);
     JSStringRelease(scriptRef);
     JSGarbageCollect(ctx);
     JSGlobalContextRelease(ctx);
@@ -126,7 +121,7 @@ void startJavaScriptThreads()
 {
     javaScriptThreadsGroup = JSContextGroupCreate();
 
-    LockHolder locker(javaScriptThreadsMutex());
+    auto locker = holdLock(javaScriptThreadsLock);
 
     for (size_t i = 0; i < javaScriptThreadsCount; ++i)
         javaScriptThreads().add(Thread::create("JavaScript Thread", &runJavaScriptThread));
@@ -135,13 +130,13 @@ void startJavaScriptThreads()
 void stopJavaScriptThreads()
 {
     {
-        LockHolder locker(javaScriptThreadsMutex());
+        auto locker = holdLock(javaScriptThreadsLock);
         javaScriptThreadsShouldTerminate = true;
     }
 
     Vector<RefPtr<Thread>, javaScriptThreadsCount> threads;
     {
-        LockHolder locker(javaScriptThreadsMutex());
+        auto locker = holdLock(javaScriptThreadsLock);
         threads = copyToVector(javaScriptThreads());
         ASSERT(threads.size() == javaScriptThreadsCount);
     }
@@ -150,7 +145,7 @@ void stopJavaScriptThreads()
         threads[i]->waitForCompletion();
 
     {
-        LockHolder locker(javaScriptThreadsMutex());
+        auto locker = holdLock(javaScriptThreadsLock);
         javaScriptThreads().clear();
     }