Changeset 220569 in webkit


Ignore:
Timestamp:
Aug 10, 2017 5:41:53 PM (7 years ago)
Author:
Yusuke Suzuki
Message:

Make ThreadGlobalData RefCounted for web thread
https://bugs.webkit.org/show_bug.cgi?id=175439

Reviewed by Mark Lam.

When the web thread is enabled, we share ThreadGlobalData between the web thread and the main thread.
The problem happens when the main thread is dying. It could start deallocating TLS and the web
thread may see the destructed ThreadGlobalData.

Even though, the current implementation is safe because the main thread do not perform TLS deallocation
in the Darwin environment. But this is not true in Windows. And we should not rely on this condition
that depends on the platforms.

In this patch, we make ThreadGlobalData ThreadSafeRefCounted. This type verbosely describes that
ThreadGlobalData could be shared between threads when the web thread enabled. And make the life time
management simple instead of relying on the platform dependent TLS implementation.

  • platform/ThreadGlobalData.cpp:

(WebCore::ThreadGlobalData::setWebCoreThreadData):
(WebCore::threadGlobalData):

  • platform/ThreadGlobalData.h:

(WebCore::ThreadGlobalData::cachedResourceRequestInitiators): Deleted.
(WebCore::ThreadGlobalData::eventNames): Deleted.
(WebCore::ThreadGlobalData::threadTimers): Deleted.
(WebCore::ThreadGlobalData::qualifiedNameCache): Deleted.
(WebCore::ThreadGlobalData::cachedConverterICU): Deleted.
(WebCore::ThreadGlobalData::cachedConverterTEC): Deleted.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r220566 r220569  
     12017-08-10  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Make ThreadGlobalData RefCounted for web thread
     4        https://bugs.webkit.org/show_bug.cgi?id=175439
     5
     6        Reviewed by Mark Lam.
     7
     8        When the web thread is enabled, we share ThreadGlobalData between the web thread and the main thread.
     9        The problem happens when the main thread is dying. It could start deallocating TLS and the web
     10        thread may see the destructed ThreadGlobalData.
     11
     12        Even though, the current implementation is safe because the main thread do not perform TLS deallocation
     13        in the Darwin environment. But this is not true in Windows. And we should not rely on this condition
     14        that depends on the platforms.
     15
     16        In this patch, we make ThreadGlobalData ThreadSafeRefCounted. This type verbosely describes that
     17        ThreadGlobalData could be shared between threads when the web thread enabled. And make the life time
     18        management simple instead of relying on the platform dependent TLS implementation.
     19
     20        * platform/ThreadGlobalData.cpp:
     21        (WebCore::ThreadGlobalData::setWebCoreThreadData):
     22        (WebCore::threadGlobalData):
     23        * platform/ThreadGlobalData.h:
     24        (WebCore::ThreadGlobalData::cachedResourceRequestInitiators): Deleted.
     25        (WebCore::ThreadGlobalData::eventNames): Deleted.
     26        (WebCore::ThreadGlobalData::threadTimers): Deleted.
     27        (WebCore::ThreadGlobalData::qualifiedNameCache): Deleted.
     28        (WebCore::ThreadGlobalData::cachedConverterICU): Deleted.
     29        (WebCore::ThreadGlobalData::cachedConverterTEC): Deleted.
     30
    1312017-08-10  Yusuke Suzuki  <utatane.tea@gmail.com>
    232
  • trunk/Source/WebCore/platform/ThreadGlobalData.cpp

    r220548 r220569  
    8282
    8383#if USE(WEB_THREAD)
    84 static ThreadSpecific<std::unique_ptr<ThreadGlobalData>>* staticData { nullptr };
     84static ThreadSpecific<RefPtr<ThreadGlobalData>>* staticData { nullptr };
    8585static ThreadGlobalData* sharedMainThreadStaticData { nullptr };
    8686
     
    9191
    9292    // Set WebThread's ThreadGlobalData object to be the same as the main UI thread.
    93     // The web thread never finishes, and we expect the main thread to also never finish.
    94     // Hence, it is safe to store the same ThreadGlobalData pointer in a thread specific std::unique_ptr.
    95     // FIXME: Make ThreadGlobalData RefCounted for web thread.
    96     // https://bugs.webkit.org/show_bug.cgi?id=175439
    97     (**staticData).reset(sharedMainThreadStaticData);
     93    **staticData = adoptRef(sharedMainThreadStaticData);
    9894
    9995    ASSERT(&threadGlobalData() == sharedMainThreadStaticData);
     
    10399{
    104100    if (UNLIKELY(!staticData)) {
    105         staticData = new ThreadSpecific<std::unique_ptr<ThreadGlobalData>>;
     101        staticData = new ThreadSpecific<RefPtr<ThreadGlobalData>>;
    106102        auto& result = **staticData;
    107103        ASSERT(!result);
    108         result.reset(new ThreadGlobalData());
     104        result = adoptRef(new ThreadGlobalData);
    109105        // WebThread and main UI thread need to share the same object. Save it in a static
    110106        // here, the WebThread will pick it up in setWebCoreThreadData().
    111         if (pthread_main_np())
     107        if (pthread_main_np()) {
    112108            sharedMainThreadStaticData = result.get();
     109            result->ref();
     110        }
    113111        return *result;
    114112    }
     
    116114    auto& result = **staticData;
    117115    if (!result)
    118         result.reset(new ThreadGlobalData());
     116        result = adoptRef(new ThreadGlobalData);
    119117    return *result;
    120118}
  • trunk/Source/WebCore/platform/ThreadGlobalData.h

    r220548 r220569  
    2828#define ThreadGlobalData_h
    2929
     30#include <wtf/ThreadSafeRefCounted.h>
    3031#include <wtf/text/StringHash.h>
    3132
     
    4041    struct TECConverterWrapper;
    4142
     43#if USE(WEB_THREAD)
     44    class ThreadGlobalData : public ThreadSafeRefCounted<ThreadGlobalData> {
     45#else
    4246    class ThreadGlobalData {
     47#endif
    4348        WTF_MAKE_NONCOPYABLE(ThreadGlobalData);
    4449        WTF_MAKE_FAST_ALLOCATED;
Note: See TracChangeset for help on using the changeset viewer.