[WTF] Thread::create should have Thread::tryCreate
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Dec 2017 10:35:39 +0000 (10:35 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Dec 2017 10:35:39 +0000 (10:35 +0000)
commit76c5157fb057bd97e2f6ddff402433e39e13e781
tree12692b3cf545cfea46d0e920601faf00cf3a6704
parent11acbce9a18b7fb007ffe31cf717469171343849
[WTF] Thread::create should have Thread::tryCreate
https://bugs.webkit.org/show_bug.cgi?id=180333

Reviewed by Darin Adler.

Source/JavaScriptCore:

* assembler/testmasm.cpp:
(JSC::run):
* b3/air/testair.cpp:
* b3/testb3.cpp:
(JSC::B3::run):
* jsc.cpp:
(functionDollarAgentStart):

Source/WebCore:

No behavior change.

* bindings/js/GCController.cpp:
(WebCore::GCController::garbageCollectOnAlternateThreadForDebugging):
* platform/audio/ReverbConvolver.cpp:
(WebCore::ReverbConvolver::ReverbConvolver):
* platform/audio/ReverbConvolver.h:
* workers/WorkerThread.cpp:
(WebCore::WorkerThread::start):

Source/WebKit:

* UIProcess/API/glib/IconDatabase.cpp:
(WebKit::IconDatabase::open):
* UIProcess/linux/MemoryPressureMonitor.cpp:
(WebKit::MemoryPressureMonitor::MemoryPressureMonitor):

Source/WebKitLegacy:

* Storage/StorageThread.cpp:
(WebCore::StorageThread::start):

Source/WebKitLegacy/win:

* WebKitQuartzCoreAdditions/CVDisplayLink.cpp:
(WKQCA::CVDisplayLink::start):

Source/WTF:

Many callers of Thread::create assume that it returns non-nullptr Thread.
But if the number of threads hits the limit in the system, creating Thread
would fail. In that case, it is really difficult to keep WebKit working.

We introduce Thread::tryCreate, and change the returned value from Thread::create
from RefPtr<Thread> to Ref<Thread>. In Thread::create, we ensure thread creation
succeeds by RELEASE_ASSERT. And we use Thread::create intentionally if the
caller assumes that thread should be created.

* wtf/AutomaticThread.cpp:
(WTF::AutomaticThread::start):
* wtf/ParallelJobsGeneric.cpp:
(WTF::ParallelEnvironment::ThreadPrivate::tryLockFor):
* wtf/Threading.cpp:
(WTF::Thread::tryCreate):
(WTF::Thread::create): Deleted.
* wtf/Threading.h:
(WTF::Thread::create):
* wtf/WorkQueue.cpp:
(WTF::WorkQueue::concurrentApply):

Tools:

* TestWebKitAPI/Tests/WTF/Condition.cpp:
* TestWebKitAPI/Tests/WTF/ParkingLot.cpp:
* TestWebKitAPI/Tests/WTF/Signals.cpp:
(TEST):
* TestWebKitAPI/Tests/WTF/ThreadGroup.cpp:
(TestWebKitAPI::testThreadGroup):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
28 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/assembler/testmasm.cpp
Source/JavaScriptCore/b3/air/testair.cpp
Source/JavaScriptCore/b3/testb3.cpp
Source/JavaScriptCore/jsc.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/AutomaticThread.cpp
Source/WTF/wtf/ParallelJobsGeneric.cpp
Source/WTF/wtf/Threading.cpp
Source/WTF/wtf/Threading.h
Source/WTF/wtf/WorkQueue.cpp
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/GCController.cpp
Source/WebCore/platform/audio/ReverbConvolver.cpp
Source/WebCore/platform/audio/ReverbConvolver.h
Source/WebCore/workers/WorkerThread.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/glib/IconDatabase.cpp
Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp
Source/WebKitLegacy/ChangeLog
Source/WebKitLegacy/Storage/StorageThread.cpp
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CVDisplayLink.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/Condition.cpp
Tools/TestWebKitAPI/Tests/WTF/ParkingLot.cpp
Tools/TestWebKitAPI/Tests/WTF/Signals.cpp
Tools/TestWebKitAPI/Tests/WTF/ThreadGroup.cpp