Changeset 49814 in webkit


Ignore:
Timestamp:
Oct 19, 2009 3:00:12 PM (15 years ago)
Author:
Adam Roben
Message:

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.

Location:
trunk/WebKit/win
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/win/ChangeLog

    r49813 r49814  
     12009-10-19  Adam Roben  <aroben@apple.com>
     2
     3        Fix crashes/assertions when calling WebLocalizedString from multiple
     4        threads concurrently
     5
     6        Fixes <http://webkit.org/b/30534> WebLocalizedString asserts if called
     7        from multiple threads concurrently
     8
     9        Reviewed by John Sullivan.
     10
     11        * WebLocalizableStrings.cpp:
     12        (mainBundleLocStringsMutex):
     13        (frameworkLocStringsMutex):
     14        Added these new getters.
     15
     16        (findCachedString):
     17        (cacheString):
     18        Lock the relevant mutex before accessing each string map. Otherwise
     19        bad things could happen if two threads end up here at the same time.
     20
    1212009-10-19  Adam Roben  <aroben@apple.com>
    222
  • trunk/WebKit/win/WebLocalizableStrings.cpp

    r49813 r49814  
    4949typedef HashMap<String, LocalizedString*> LocalizedStringMap;
    5050
     51static Mutex& mainBundleLocStringsMutex()
     52{
     53    DEFINE_STATIC_LOCAL(Mutex, mutex, ());
     54    return mutex;
     55}
     56
    5157static LocalizedStringMap& mainBundleLocStrings()
    5258{
    5359    DEFINE_STATIC_LOCAL(LocalizedStringMap, map, ());
    5460    return map;
     61}
     62
     63static Mutex& frameworkLocStringsMutex()
     64{
     65    DEFINE_STATIC_LOCAL(Mutex, mutex, ());
     66    return mutex;
    5567}
    5668
     
    169181static LocalizedString* findCachedString(WebLocalizableStringsBundle* stringsBundle, const String& key)
    170182{
    171     if (!stringsBundle)
     183    if (!stringsBundle) {
     184        MutexLocker lock(mainBundleLocStringsMutex());
    172185        return mainBundleLocStrings().get(key);
    173 
    174     if (stringsBundle->bundle == WebKitLocalizableStringsBundle.bundle)
     186    }
     187
     188    if (stringsBundle->bundle == WebKitLocalizableStringsBundle.bundle) {
     189        MutexLocker lock(frameworkLocStringsMutex());
    175190        return frameworkLocStrings().get(key);
     191    }
    176192
    177193    return 0;
     
    181197{
    182198    if (!stringsBundle) {
     199        MutexLocker lock(mainBundleLocStringsMutex());
    183200        mainBundleLocStrings().set(key, value);
    184201        return;
    185202    }
    186203
     204    MutexLocker lock(frameworkLocStringsMutex());
    187205    frameworkLocStrings().set(key, value);
    188206}
Note: See TracChangeset for help on using the changeset viewer.