⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 225938 in webkit


Ignore:
Timestamp:
Dec 14, 2017, 3:51:05 PM (9 years ago)
Author:
Yusuke Suzuki
Message:

Drop Thread::tryCreate
​https://bugs.webkit.org/show_bug.cgi?id=180808

Reviewed by Darin Adler.

Source/WebCore:

This change reveals that nobody cares the WorkerThread::start's failure.
We should use Thread::create to ensure thread is actually starting.

  • workers/WorkerThread.cpp:

(WebCore::WorkerThread::start):

  • workers/WorkerThread.h:

Source/WebKit:

We still return bool since IconDatabase::open returns false if it is opened twice.

  • UIProcess/API/glib/IconDatabase.cpp:

(WebKit::IconDatabase::open):

  • UIProcess/API/glib/IconDatabase.h:

Source/WebKitLegacy:

  • Storage/StorageThread.cpp:

(WebCore::StorageThread::start):

  • Storage/StorageThread.h:

Source/WTF:

We remove Thread::tryCreate. When thread creation fails, we have no way to keep WebKit working.
Compared to tryMalloc, Thread::create always consumes fixed size of resource. If it fails,
this is not due to arbitrary large user request. It is not reasonable that some thread creations
are handled gracefully while the other thread creations are not.

If we would like to have the limit of number of users' thread creation (like, calling new Worker
so many times), we should have a soft limit instead of relying on system's hard limit.

  • wtf/ParallelJobsGeneric.cpp:

(WTF::ParallelEnvironment::ThreadPrivate::tryLockFor):

  • wtf/Threading.cpp:

(WTF::Thread::create):
(WTF::Thread::tryCreate): Deleted.

  • wtf/Threading.h:

(WTF::Thread::create): Deleted.

Location:
trunk/Source
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r225913 r225938  
     12017-12-14  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Drop Thread::tryCreate
     4        https://bugs.webkit.org/show_bug.cgi?id=180808
     5
     6        Reviewed by Darin Adler.
     7
     8        We remove Thread::tryCreate. When thread creation fails, we have no way to keep WebKit working.
     9        Compared to tryMalloc, Thread::create always consumes fixed size of resource. If it fails,
     10        this is not due to arbitrary large user request. It is not reasonable that some thread creations
     11        are handled gracefully while the other thread creations are not.
     12
     13        If we would like to have the limit of number of users' thread creation (like, calling `new Worker`
     14        so many times), we should have a soft limit instead of relying on system's hard limit.
     15
     16        * wtf/ParallelJobsGeneric.cpp:
     17        (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor):
     18        * wtf/Threading.cpp:
     19        (WTF::Thread::create):
     20        (WTF::Thread::tryCreate): Deleted.
     21        * wtf/Threading.h:
     22        (WTF::Thread::create): Deleted.
     23
    1242017-12-13  Keith Miller  <keith_miller@apple.com>
    225
  • trunk/Source/WTF/wtf/ParallelJobsGeneric.cpp

    r225778 r225938  
    9595
    9696    if (!m_thread) {
    97         m_thread = Thread::tryCreate("Parallel worker", [this] {
     97        m_thread = Thread::create("Parallel worker", [this] {
    9898            LockHolder lock(m_mutex);
    9999
    100             while (m_thread) {
     100            while (true) {
    101101                if (m_running) {
    102102                    (*m_threadFunction)(m_parameters);
    103103                    m_running = false;
    104                     m_parent = 0;
     104                    m_parent = nullptr;
    105105                    m_threadCondition.notifyOne();
    106106                }
    … …  
    110110        });
    111111    }
    112 
    113     if (m_thread)
    114         m_parent = parent;
     112    m_parent = parent;
    115113
    116114    m_mutex.unlock();
    117     return m_thread;
     115    return true;
    118116}
    119117
  • trunk/Source/WTF/wtf/Threading.cpp

    r225778 r225938  
    130130}
    131131
    132 RefPtr<Thread> Thread::tryCreate(const char* name, Function<void()>&& entryPoint)
     132Ref<Thread> Thread::create(const char* name, Function<void()>&& entryPoint)
    133133{
    134134    WTF::initializeThreading();
    … …  
    143143    {
    144144        MutexLocker locker(context->mutex);
    145         if (!thread->establishHandle(context.ptr())) {
    146             context->deref();
    147             return nullptr;
    148         }
     145        bool success = thread->establishHandle(context.ptr());
     146        RELEASE_ASSERT(success);
    149147        context->stage = NewThreadContext::Stage::EstablishedHandle;
    150148
    … …  
    161159
    162160    ASSERT(!thread->stack().isEmpty());
    163     return WTFMove(thread);
     161    return thread;
    164162}
    165163
  • trunk/Source/WTF/wtf/Threading.h

    r225778 r225938  
    8787    // Returns nullptr if thread creation failed.
    8888    // The thread name must be a literal since on some platforms it's passed in to the thread.
    89     WTF_EXPORT_PRIVATE static RefPtr<Thread> tryCreate(const char* threadName, Function<void()>&&);
    90     static inline Ref<Thread> create(const char* threadName, Function<void()>&& function)
    91     {
    92         auto thread = tryCreate(threadName, WTFMove(function));
    93         RELEASE_ASSERT(thread);
    94         return thread.releaseNonNull();
    95     }
     89    WTF_EXPORT_PRIVATE static Ref<Thread> create(const char* threadName, Function<void()>&&);
    9690
    9791    // Returns Thread object.
  • trunk/Source/WebCore/ChangeLog

    r225936 r225938  
     12017-12-14  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Drop Thread::tryCreate
     4        https://bugs.webkit.org/show_bug.cgi?id=180808
     5
     6        Reviewed by Darin Adler.
     7
     8        This change reveals that nobody cares the WorkerThread::start's failure.
     9        We should use `Thread::create` to ensure thread is actually starting.
     10
     11        * workers/WorkerThread.cpp:
     12        (WebCore::WorkerThread::start):
     13        * workers/WorkerThread.h:
     14
    1152017-12-14  Alicia Boya García  <aboya@igalia.com>
    216
  • trunk/Source/WebCore/workers/WorkerThread.cpp

    r225778 r225938  
    131131}
    132132
    133 bool WorkerThread::start(WTF::Function<void(const String&)>&& evaluateCallback)
     133void WorkerThread::start(WTF::Function<void(const String&)>&& evaluateCallback)
    134134{
    135135    // Mutex protection is necessary to ensure that m_thread is initialized when the thread starts.
    … …  
    137137
    138138    if (m_thread)
    139         return true;
     139        return;
    140140
    141141    m_evaluateCallback = WTFMove(evaluateCallback);
    142142
    143     m_thread = Thread::tryCreate("WebCore: Worker", [this] {
     143    m_thread = Thread::create("WebCore: Worker", [this] {
    144144        workerThread();
    145145    });
    146 
    147     return m_thread;
    148146}
    149147
  • trunk/Source/WebCore/workers/WorkerThread.h

    r225470 r225938  
    6464    virtual ~WorkerThread();
    6565
    66     WEBCORE_EXPORT bool start(WTF::Function<void(const String&)>&& evaluateCallback);
     66    WEBCORE_EXPORT void start(WTF::Function<void(const String&)>&& evaluateCallback);
    6767    void stop(WTF::Function<void()>&& terminatedCallback);
    6868
  • trunk/Source/WebKit/ChangeLog

    r225935 r225938  
     12017-12-14  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Drop Thread::tryCreate
     4        https://bugs.webkit.org/show_bug.cgi?id=180808
     5
     6        Reviewed by Darin Adler.
     7
     8        We still return bool since IconDatabase::open returns `false` if it is opened twice.
     9
     10        * UIProcess/API/glib/IconDatabase.cpp:
     11        (WebKit::IconDatabase::open):
     12        * UIProcess/API/glib/IconDatabase.h:
     13
    1142017-12-14  Brady Eidson  <beidson@apple.com>
    215
  • trunk/Source/WebKit/UIProcess/API/glib/IconDatabase.cpp

    r225778 r225938  
    220220    // completes and m_syncThreadRunning is properly set
    221221    m_syncLock.lock();
    222     m_syncThread = Thread::tryCreate("WebCore: IconDatabase", [this] {
     222    m_syncThread = Thread::create("WebCore: IconDatabase", [this] {
    223223        iconDatabaseSyncThread();
    224224    });
    225     m_syncThreadRunning = m_syncThread;
     225    m_syncThreadRunning = true;
    226226    m_syncLock.unlock();
    227     if (!m_syncThread)
    228         return false;
    229227    return true;
    230228}
  • trunk/Source/WebKit/UIProcess/API/glib/IconDatabase.h

    r221238 r225938  
    286286    PageURLRecord* getOrCreatePageURLRecord(const String& pageURL);
    287287
    288     bool m_isEnabled {false };
     288    bool m_isEnabled { false };
    289289    bool m_privateBrowsingEnabled { false };
    290290
  • trunk/Source/WebKitLegacy/ChangeLog

    r225778 r225938  
     12017-12-14  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Drop Thread::tryCreate
     4        https://bugs.webkit.org/show_bug.cgi?id=180808
     5
     6        Reviewed by Darin Adler.
     7
     8        * Storage/StorageThread.cpp:
     9        (WebCore::StorageThread::start):
     10        * Storage/StorageThread.h:
     11
    1122017-12-12  Yusuke Suzuki  <utatane.tea@gmail.com>
    213
  • trunk/Source/WebKitLegacy/Storage/StorageThread.cpp

    r225778 r225938  
    5151}
    5252
    53 bool StorageThread::start()
     53void StorageThread::start()
    5454{
    5555    ASSERT(isMainThread());
    5656    if (!m_thread) {
    57         m_thread = Thread::tryCreate("WebCore: LocalStorage", [this] {
     57        m_thread = Thread::create("WebCore: LocalStorage", [this] {
    5858            threadEntryPoint();
    5959        });
    6060    }
    6161    activeStorageThreads().add(this);
    62     return m_thread;
    6362}
    6463
  • trunk/Source/WebKitLegacy/Storage/StorageThread.h

    r218816 r225938  
    4242    ~StorageThread();
    4343
    44     bool start();
     44    void start();
    4545    void terminate();
    4646
Note: See TracChangeset for help on using the changeset viewer.