Changeset 207071 in webkit


Ignore:
Timestamp:
Oct 11, 2016 2:23:28 AM (8 years ago)
Author:
Carlos Garcia Campos
Message:

Merge r205859 - ParkingLot is going to have a bad time with threads dying
https://bugs.webkit.org/show_bug.cgi?id=161893

Reviewed by Michael Saboff.

If a thread dies right as it falls out of parkConditionally, then unparkOne() and friends
might die because they will dereference a deallocated ThreadData.

The solution is to ref-count ThreadData's. When unparkOne() and friends want to hold onto a
ThreadData past the queue lock, they can use RefPtr<>.

  • wtf/ParkingLot.cpp:

(WTF::ParkingLot::unparkOne):
(WTF::ParkingLot::unparkOneImpl):
(WTF::ParkingLot::unparkAll):

Location:
releases/WebKitGTK/webkit-2.14/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.14/Source/WTF/ChangeLog

    r207070 r207071  
     12016-09-12  Filip Pizlo  <fpizlo@apple.com>
     2
     3        ParkingLot is going to have a bad time with threads dying
     4        https://bugs.webkit.org/show_bug.cgi?id=161893
     5
     6        Reviewed by Michael Saboff.
     7       
     8        If a thread dies right as it falls out of parkConditionally, then unparkOne() and friends
     9        might die because they will dereference a deallocated ThreadData.
     10
     11        The solution is to ref-count ThreadData's. When unparkOne() and friends want to hold onto a
     12        ThreadData past the queue lock, they can use RefPtr<>.
     13
     14        * wtf/ParkingLot.cpp:
     15        (WTF::ParkingLot::unparkOne):
     16        (WTF::ParkingLot::unparkOneImpl):
     17        (WTF::ParkingLot::unparkAll):
     18
    1192016-09-12  Yusuke Suzuki  <utatane.tea@gmail.com>
    220
  • releases/WebKitGTK/webkit-2.14/Source/WTF/wtf/ParkingLot.cpp

    r205717 r207071  
    4646const bool verbose = false;
    4747
    48 struct ThreadData {
     48struct ThreadData : public ThreadSafeRefCounted<ThreadData> {
    4949    WTF_MAKE_FAST_ALLOCATED;
    5050public:
     
    246246};
    247247
    248 ThreadSpecific<ThreadData>* threadData;
    249248Atomic<Hashtable*> hashtable;
    250249Atomic<unsigned> numThreads;
     
    449448ThreadData* myThreadData()
    450449{
     450    static ThreadSpecific<RefPtr<ThreadData>>* threadData;
    451451    static std::once_flag initializeOnce;
    452452    std::call_once(
    453453        initializeOnce,
    454454        [] {
    455             threadData = new ThreadSpecific<ThreadData>();
     455            threadData = new ThreadSpecific<RefPtr<ThreadData>>();
    456456        });
    457 
    458     return *threadData;
     457   
     458    RefPtr<ThreadData>& result = **threadData;
     459   
     460    if (!result)
     461        result = adoptRef(new ThreadData());
     462   
     463    return result.get();
    459464}
    460465
     
    660665    UnparkResult result;
    661666
    662     ThreadData* threadData = nullptr;
     667    RefPtr<ThreadData> threadData;
    663668    result.mayHaveMoreThreads = dequeue(
    664669        address,
     
    698703        dataLog(toString(currentThread(), ": unparking one the hard way.\n"));
    699704   
    700     ThreadData* threadData = nullptr;
     705    RefPtr<ThreadData> threadData;
    701706    bool timeToBeFair = false;
    702707    dequeue(
     
    739744        dataLog(toString(currentThread(), ": unparking all from ", RawPointer(address), ".\n"));
    740745   
    741     Vector<ThreadData*, 8> threadDatas;
     746    Vector<RefPtr<ThreadData>, 8> threadDatas;
    742747    dequeue(
    743748        address,
     
    753758        [] (bool) { });
    754759
    755     for (ThreadData* threadData : threadDatas) {
     760    for (RefPtr<ThreadData>& threadData : threadDatas) {
    756761        if (verbose)
    757             dataLog(toString(currentThread(), ": unparking ", RawPointer(threadData), " with address ", RawPointer(threadData->address), "\n"));
     762            dataLog(toString(currentThread(), ": unparking ", RawPointer(threadData.get()), " with address ", RawPointer(threadData->address), "\n"));
    758763        ASSERT(threadData->address);
    759764        {
Note: See TracChangeset for help on using the changeset viewer.