Modified: trunk/Source/WebCore/ChangeLog (161834 => 161835)
--- trunk/Source/WebCore/ChangeLog 2014-01-12 21:23:45 UTC (rev 161834)
+++ trunk/Source/WebCore/ChangeLog 2014-01-12 21:31:09 UTC (rev 161835)
@@ -1,3 +1,22 @@
+2014-01-12 Anders Carlsson <[email protected]>
+
+ Use std::call_once instead of AtomicallyInitializedStatic in DatabaseBackendBase
+ https://bugs.webkit.org/show_bug.cgi?id=126851
+
+ Reviewed by Sam Weinig.
+
+ * Modules/webdatabase/DatabaseBackendBase.cpp:
+ (WebCore::guidMutex):
+ (WebCore::guidToVersionMap):
+ (WebCore::updateGuidVersionMap):
+ (WebCore::guidToDatabaseMap):
+ (WebCore::guidForOriginAndName):
+ (WebCore::DatabaseBackendBase::DatabaseBackendBase):
+ (WebCore::DatabaseBackendBase::closeDatabase):
+ (WebCore::DatabaseBackendBase::performOpenAndVerify):
+ (WebCore::DatabaseBackendBase::getCachedVersion):
+ (WebCore::DatabaseBackendBase::setCachedVersion):
+
2014-01-12 Dan Bernstein <[email protected]>
Try to fix the Windows build after r161830.
Modified: trunk/Source/WebCore/Modules/webdatabase/DatabaseBackendBase.cpp (161834 => 161835)
--- trunk/Source/WebCore/Modules/webdatabase/DatabaseBackendBase.cpp 2014-01-12 21:23:45 UTC (rev 161834)
+++ trunk/Source/WebCore/Modules/webdatabase/DatabaseBackendBase.cpp 2014-01-12 21:31:09 UTC (rev 161835)
@@ -141,18 +141,25 @@
}
// FIXME: move all guid-related functions to a DatabaseVersionTracker class.
-static Mutex& guidMutex()
+static std::mutex& guidMutex()
{
- AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
- return mutex;
+ static std::once_flag onceFlag;
+ static std::mutex* mutex;
+
+ std::call_once(onceFlag, []{
+ mutex = std::make_unique<std::mutex>().release();
+ });
+
+ return *mutex;
}
typedef HashMap<DatabaseGuid, String> GuidVersionMap;
static GuidVersionMap& guidToVersionMap()
{
// Ensure the the mutex is locked.
- ASSERT(!guidMutex().tryLock());
- DEFINE_STATIC_LOCAL(GuidVersionMap, map, ());
+ ASSERT(!guidMutex().try_lock());
+
+ static NeverDestroyed<GuidVersionMap> map;
return map;
}
@@ -160,7 +167,7 @@
static inline void updateGuidVersionMap(DatabaseGuid guid, String newVersion)
{
// Ensure the the mutex is locked.
- ASSERT(!guidMutex().tryLock());
+ ASSERT(!guidMutex().try_lock());
// Note: It is not safe to put an empty string into the guidToVersionMap() map.
// That's because the map is cross-thread, but empty strings are per-thread.
@@ -177,7 +184,8 @@
static GuidDatabaseMap& guidToDatabaseMap()
{
// Ensure the the mutex is locked.
- ASSERT(!guidMutex().tryLock());
+ ASSERT(!guidMutex().try_lock());
+
static NeverDestroyed<GuidDatabaseMap> map;
return map;
}
@@ -185,7 +193,7 @@
static DatabaseGuid guidForOriginAndName(const String& origin, const String& name)
{
// Ensure the the mutex is locked.
- ASSERT(!guidMutex().tryLock());
+ ASSERT(!guidMutex().try_lock());
String stringID = origin + "/" + name;
@@ -233,7 +241,8 @@
m_name = emptyString();
{
- MutexLocker locker(guidMutex());
+ std::lock_guard<std::mutex> locker(guidMutex());
+
m_guid = guidForOriginAndName(securityOrigin()->toString(), name);
std::unique_ptr<HashSet<DatabaseBackendBase*>>& hashSet = guidToDatabaseMap().add(m_guid, nullptr).iterator->value;
if (!hashSet)
@@ -268,7 +277,7 @@
// See comment at the top this file regarding calling removeOpenDatabase().
DatabaseTracker::tracker().removeOpenDatabase(this);
{
- MutexLocker locker(guidMutex());
+ std::lock_guard<std::mutex> locker(guidMutex());
auto it = guidToDatabaseMap().find(m_guid);
ASSERT(it != guidToDatabaseMap().end());
@@ -337,7 +346,7 @@
String currentVersion;
{
- MutexLocker locker(guidMutex());
+ std::lock_guard<std::mutex> locker(guidMutex());
auto entry = guidToVersionMap().find(m_guid);
if (entry != guidToVersionMap().end()) {
@@ -496,14 +505,16 @@
String DatabaseBackendBase::getCachedVersion() const
{
- MutexLocker locker(guidMutex());
+ std::lock_guard<std::mutex> locker(guidMutex());
+
return guidToVersionMap().get(m_guid).isolatedCopy();
}
void DatabaseBackendBase::setCachedVersion(const String& actualVersion)
{
// Update the in memory database version map.
- MutexLocker locker(guidMutex());
+ std::lock_guard<std::mutex> locker(guidMutex());
+
updateGuidVersionMap(m_guid, actualVersion);
}