Changeset 275500 in webkit


Ignore:
Timestamp:
Apr 6, 2021 2:59:36 AM (3 years ago)
Author:
Chris Lord
Message:

BidiContext caching is not thread-safe
https://bugs.webkit.org/show_bug.cgi?id=224179

Reviewed by Darin Adler.

Make BidiContext ThreadSafeRefCounted and make shared context creation
thread-safe. This is needed by OffscreenCanvas to use text in Workers.

No new tests, covered by existing tests.

  • platform/text/BidiContext.cpp:

(WebCore::BidiContext::create):

  • platform/text/BidiContext.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r275498 r275500  
     12021-04-06  Chris Lord  <clord@igalia.com>
     2
     3        BidiContext caching is not thread-safe
     4        https://bugs.webkit.org/show_bug.cgi?id=224179
     5
     6        Reviewed by Darin Adler.
     7
     8        Make BidiContext ThreadSafeRefCounted and make shared context creation
     9        thread-safe. This is needed by OffscreenCanvas to use text in Workers.
     10
     11        No new tests, covered by existing tests.
     12
     13        * platform/text/BidiContext.cpp:
     14        (WebCore::BidiContext::create):
     15        * platform/text/BidiContext.h:
     16
    1172021-04-06  Frédéric Wang  <fwang@igalia.com>
    218
  • trunk/Source/WebCore/platform/text/BidiContext.cpp

    r210492 r275500  
    2727namespace WebCore {
    2828
    29 struct SameSizeAsBidiContext : public RefCounted<SameSizeAsBidiContext> {
     29struct SameSizeAsBidiContext : public ThreadSafeRefCounted<SameSizeAsBidiContext> {
    3030    uint32_t bitfields : 16;
    3131    void* parent;
     
    5858    if (!level) {
    5959        if (!override) {
    60             static BidiContext& ltrContext = createUncached(0, U_LEFT_TO_RIGHT, false, FromStyleOrDOM, 0).leakRef();
    61             return ltrContext;
     60            static NeverDestroyed<RefPtr<BidiContext>> ltrContext;
     61            static std::once_flag ltrContextOnceFlag;
     62            std::call_once(ltrContextOnceFlag, [&]() {
     63                ltrContext.get() = createUncached(0, U_LEFT_TO_RIGHT, false, FromStyleOrDOM, 0);
     64            });
     65            return *ltrContext.get();
    6266        }
    6367
    64         static BidiContext& ltrOverrideContext = createUncached(0, U_LEFT_TO_RIGHT, true, FromStyleOrDOM, 0).leakRef();
    65         return ltrOverrideContext;
     68        static NeverDestroyed<RefPtr<BidiContext>> ltrOverrideContext;
     69        static std::once_flag ltrOverrideContextOnceFlag;
     70        std::call_once(ltrOverrideContextOnceFlag, [&]() {
     71            ltrOverrideContext.get() = createUncached(0, U_LEFT_TO_RIGHT, true, FromStyleOrDOM, 0);
     72        });
     73        return *ltrOverrideContext.get();
    6674    }
    6775
    6876    if (!override) {
    69         static BidiContext& rtlContext = createUncached(1, U_RIGHT_TO_LEFT, false, FromStyleOrDOM, 0).leakRef();
    70         return rtlContext;
     77        static NeverDestroyed<RefPtr<BidiContext>> rtlContext;
     78        static std::once_flag rtlContextOnceFlag;
     79        std::call_once(rtlContextOnceFlag, [&]() {
     80            rtlContext.get() = createUncached(1, U_RIGHT_TO_LEFT, false, FromStyleOrDOM, 0);
     81        });
     82        return *rtlContext.get();
    7183    }
    7284
    73     static BidiContext& rtlOverrideContext = createUncached(1, U_RIGHT_TO_LEFT, true, FromStyleOrDOM, 0).leakRef();
    74     return rtlOverrideContext;
     85    static NeverDestroyed<RefPtr<BidiContext>> rtlOverrideContext;
     86    static std::once_flag rtlOverrideContextOnceFlag;
     87    std::call_once(rtlOverrideContextOnceFlag, [&]() {
     88        rtlOverrideContext.get() = createUncached(1, U_RIGHT_TO_LEFT, true, FromStyleOrDOM, 0);
     89    });
     90    return *rtlOverrideContext.get();
    7591}
    7692
  • trunk/Source/WebCore/platform/text/BidiContext.h

    r210492 r275500  
    2323
    2424#include <unicode/uchar.h>
    25 #include <wtf/RefCounted.h>
    2625#include <wtf/RefPtr.h>
     26#include <wtf/ThreadSafeRefCounted.h>
    2727
    2828namespace WebCore {
     
    3131
    3232// Used to keep track of explicit embeddings.
    33 class BidiContext : public RefCounted<BidiContext> {
     33class BidiContext : public ThreadSafeRefCounted<BidiContext> {
    3434public:
    3535    WEBCORE_EXPORT static Ref<BidiContext> create(unsigned char level, UCharDirection, bool override = false, BidiEmbeddingSource = FromStyleOrDOM, BidiContext* parent = nullptr);
Note: See TracChangeset for help on using the changeset viewer.