Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix crashes/assertions when calling WebLocalizedString from multiple …
…threads concurrently

Fixes <http://webkit.org/b/30534> WebLocalizedString asserts if called
from multiple threads concurrently

Reviewed by John Sullivan.

* WebLocalizableStrings.cpp:
(mainBundleLocStringsMutex):
(frameworkLocStringsMutex):
Added these new getters.

(findCachedString):
(cacheString):
Lock the relevant mutex before accessing each string map. Otherwise
bad things could happen if two threads end up here at the same time.

Canonical link: https://commits.webkit.org/41268@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@49814 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
aroben committed Oct 19, 2009
1 parent 2764068 commit bd9149b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
20 changes: 20 additions & 0 deletions WebKit/win/ChangeLog
@@ -1,3 +1,23 @@
2009-10-19 Adam Roben <aroben@apple.com>

Fix crashes/assertions when calling WebLocalizedString from multiple
threads concurrently

Fixes <http://webkit.org/b/30534> WebLocalizedString asserts if called
from multiple threads concurrently

Reviewed by John Sullivan.

* WebLocalizableStrings.cpp:
(mainBundleLocStringsMutex):
(frameworkLocStringsMutex):
Added these new getters.

(findCachedString):
(cacheString):
Lock the relevant mutex before accessing each string map. Otherwise
bad things could happen if two threads end up here at the same time.

2009-10-19 Adam Roben <aroben@apple.com>

Get rid of a few static initializers/exit-time destructors in
Expand Down
22 changes: 20 additions & 2 deletions WebKit/win/WebLocalizableStrings.cpp
Expand Up @@ -48,12 +48,24 @@ WebLocalizableStringsBundle WebKitLocalizableStringsBundle = { "com.apple.WebKit

typedef HashMap<String, LocalizedString*> LocalizedStringMap;

static Mutex& mainBundleLocStringsMutex()
{
DEFINE_STATIC_LOCAL(Mutex, mutex, ());
return mutex;
}

static LocalizedStringMap& mainBundleLocStrings()
{
DEFINE_STATIC_LOCAL(LocalizedStringMap, map, ());
return map;
}

static Mutex& frameworkLocStringsMutex()
{
DEFINE_STATIC_LOCAL(Mutex, mutex, ());
return mutex;
}

static LocalizedStringMap frameworkLocStrings()
{
DEFINE_STATIC_LOCAL(LocalizedStringMap, map, ());
Expand Down Expand Up @@ -168,22 +180,28 @@ static CFStringRef copyLocalizedStringFromBundle(WebLocalizableStringsBundle* st

static LocalizedString* findCachedString(WebLocalizableStringsBundle* stringsBundle, const String& key)
{
if (!stringsBundle)
if (!stringsBundle) {
MutexLocker lock(mainBundleLocStringsMutex());
return mainBundleLocStrings().get(key);
}

if (stringsBundle->bundle == WebKitLocalizableStringsBundle.bundle)
if (stringsBundle->bundle == WebKitLocalizableStringsBundle.bundle) {
MutexLocker lock(frameworkLocStringsMutex());
return frameworkLocStrings().get(key);
}

return 0;
}

static void cacheString(WebLocalizableStringsBundle* stringsBundle, const String& key, LocalizedString* value)
{
if (!stringsBundle) {
MutexLocker lock(mainBundleLocStringsMutex());
mainBundleLocStrings().set(key, value);
return;
}

MutexLocker lock(frameworkLocStringsMutex());
frameworkLocStrings().set(key, value);
}

Expand Down

0 comments on commit bd9149b

Please sign in to comment.