Title: [233123] trunk/Source
Revision
233123
Author
[email protected]
Date
2018-06-23 02:59:04 -0700 (Sat, 23 Jun 2018)

Log Message

[WTF] Use Ref<> for the result type of non-failing factory functions
https://bugs.webkit.org/show_bug.cgi?id=186920

Reviewed by Darin Adler.

Source/_javascript_Core:

* dfg/DFGWorklist.cpp:
(JSC::DFG::Worklist::ThreadBody::ThreadBody):
(JSC::DFG::Worklist::finishCreation):
* dfg/DFGWorklist.h:
* heap/Heap.cpp:
(JSC::Heap::Thread::Thread):
* heap/Heap.h:
* jit/JITWorklist.cpp:
(JSC::JITWorklist::Thread::Thread):
* jit/JITWorklist.h:
* runtime/VMTraps.cpp:
* runtime/VMTraps.h:
* wasm/WasmWorklist.cpp:
* wasm/WasmWorklist.h:

Source/WTF:

Use Ref<> instead of RefPtr<> if the `create` function do not return nullptr.

* wtf/AutomaticThread.cpp:
(WTF::AutomaticThreadCondition::create):
(WTF::AutomaticThread::AutomaticThread):
* wtf/AutomaticThread.h:
* wtf/ParallelHelperPool.cpp:
(WTF::ParallelHelperPool::Thread::Thread):
* wtf/ParallelHelperPool.h:
* wtf/WorkerPool.cpp:
(WTF::WorkerPool::WorkerPool):
* wtf/WorkerPool.h:
* wtf/win/WorkQueueWin.cpp:
(WTF::TimerContext::create):
(WTF::WorkQueue::dispatchAfter):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (233122 => 233123)


--- trunk/Source/_javascript_Core/ChangeLog	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-06-23 09:59:04 UTC (rev 233123)
@@ -1,3 +1,25 @@
+2018-06-22  Yusuke Suzuki  <[email protected]>
+
+        [WTF] Use Ref<> for the result type of non-failing factory functions
+        https://bugs.webkit.org/show_bug.cgi?id=186920
+
+        Reviewed by Darin Adler.
+
+        * dfg/DFGWorklist.cpp:
+        (JSC::DFG::Worklist::ThreadBody::ThreadBody):
+        (JSC::DFG::Worklist::finishCreation):
+        * dfg/DFGWorklist.h:
+        * heap/Heap.cpp:
+        (JSC::Heap::Thread::Thread):
+        * heap/Heap.h:
+        * jit/JITWorklist.cpp:
+        (JSC::JITWorklist::Thread::Thread):
+        * jit/JITWorklist.h:
+        * runtime/VMTraps.cpp:
+        * runtime/VMTraps.h:
+        * wasm/WasmWorklist.cpp:
+        * wasm/WasmWorklist.h:
+
 2018-06-23  Yusuke Suzuki  <[email protected]>
 
         [WTF] Add user-defined literal for ASCIILiteral

Modified: trunk/Source/_javascript_Core/dfg/DFGWorklist.cpp (233122 => 233123)


--- trunk/Source/_javascript_Core/dfg/DFGWorklist.cpp	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/dfg/DFGWorklist.cpp	2018-06-23 09:59:04 UTC (rev 233123)
@@ -39,8 +39,8 @@
 
 class Worklist::ThreadBody : public AutomaticThread {
 public:
-    ThreadBody(const AbstractLocker& locker, Worklist& worklist, ThreadData& data, Box<Lock> lock, RefPtr<AutomaticThreadCondition> condition, int relativePriority)
-        : AutomaticThread(locker, lock, condition)
+    ThreadBody(const AbstractLocker& locker, Worklist& worklist, ThreadData& data, Box<Lock> lock, Ref<AutomaticThreadCondition>&& condition, int relativePriority)
+        : AutomaticThread(locker, lock, WTFMove(condition))
         , m_worklist(worklist)
         , m_data(data)
         , m_relativePriority(relativePriority)
@@ -201,7 +201,7 @@
     LockHolder locker(*m_lock);
     for (unsigned i = numberOfThreads; i--;) {
         std::unique_ptr<ThreadData> data = ""
-        data->m_thread = adoptRef(new ThreadBody(locker, *this, *data, m_lock, m_planEnqueued, relativePriority));
+        data->m_thread = adoptRef(new ThreadBody(locker, *this, *data, m_lock, m_planEnqueued.copyRef(), relativePriority));
         m_threads.append(WTFMove(data));
     }
 }

Modified: trunk/Source/_javascript_Core/dfg/DFGWorklist.h (233122 => 233123)


--- trunk/Source/_javascript_Core/dfg/DFGWorklist.h	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/dfg/DFGWorklist.h	2018-06-23 09:59:04 UTC (rev 233123)
@@ -113,7 +113,7 @@
     Lock m_suspensionLock;
     
     Box<Lock> m_lock;
-    RefPtr<AutomaticThreadCondition> m_planEnqueued;
+    Ref<AutomaticThreadCondition> m_planEnqueued;
     Condition m_planCompiled;
     
     Vector<std::unique_ptr<ThreadData>> m_threads;

Modified: trunk/Source/_javascript_Core/heap/Heap.cpp (233122 => 233123)


--- trunk/Source/_javascript_Core/heap/Heap.cpp	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/heap/Heap.cpp	2018-06-23 09:59:04 UTC (rev 233123)
@@ -234,7 +234,7 @@
 class Heap::Thread : public AutomaticThread {
 public:
     Thread(const AbstractLocker& locker, Heap& heap)
-        : AutomaticThread(locker, heap.m_threadLock, heap.m_threadCondition)
+        : AutomaticThread(locker, heap.m_threadLock, heap.m_threadCondition.copyRef())
         , m_heap(heap)
     {
     }

Modified: trunk/Source/_javascript_Core/heap/Heap.h (233122 => 233123)


--- trunk/Source/_javascript_Core/heap/Heap.h	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/heap/Heap.h	2018-06-23 09:59:04 UTC (rev 233123)
@@ -701,7 +701,7 @@
     uint64_t m_mutatorExecutionVersion { 0 };
     uint64_t m_phaseVersion { 0 };
     Box<Lock> m_threadLock;
-    RefPtr<AutomaticThreadCondition> m_threadCondition; // The mutator must not wait on this. It would cause a deadlock.
+    Ref<AutomaticThreadCondition> m_threadCondition; // The mutator must not wait on this. It would cause a deadlock.
     RefPtr<AutomaticThread> m_thread;
 
 #if PLATFORM(IOS)

Modified: trunk/Source/_javascript_Core/jit/JITWorklist.cpp (233122 => 233123)


--- trunk/Source/_javascript_Core/jit/JITWorklist.cpp	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/jit/JITWorklist.cpp	2018-06-23 09:59:04 UTC (rev 233123)
@@ -100,7 +100,7 @@
 class JITWorklist::Thread : public AutomaticThread {
 public:
     Thread(const AbstractLocker& locker, JITWorklist& worklist)
-        : AutomaticThread(locker, worklist.m_lock, worklist.m_condition)
+        : AutomaticThread(locker, worklist.m_lock, worklist.m_condition.copyRef())
         , m_worklist(worklist)
     {
         m_worklist.m_numAvailableThreads++;

Modified: trunk/Source/_javascript_Core/jit/JITWorklist.h (233122 => 233123)


--- trunk/Source/_javascript_Core/jit/JITWorklist.h	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/jit/JITWorklist.h	2018-06-23 09:59:04 UTC (rev 233123)
@@ -72,7 +72,7 @@
     HashSet<CodeBlock*> m_planned;
     
     Box<Lock> m_lock;
-    RefPtr<AutomaticThreadCondition> m_condition; // We use One True Condition for everything because that's easier.
+    Ref<AutomaticThreadCondition> m_condition; // We use One True Condition for everything because that's easier.
     RefPtr<AutomaticThread> m_thread;
     
     unsigned m_numAvailableThreads { 0 };

Modified: trunk/Source/_javascript_Core/runtime/VMTraps.cpp (233122 => 233123)


--- trunk/Source/_javascript_Core/runtime/VMTraps.cpp	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/runtime/VMTraps.cpp	2018-06-23 09:59:04 UTC (rev 233123)
@@ -180,7 +180,7 @@
 public:
     using Base = AutomaticThread;
     SignalSender(const AbstractLocker& locker, VM& vm)
-        : Base(locker, vm.traps().m_lock, vm.traps().m_trapSet)
+        : Base(locker, vm.traps().m_lock, vm.traps().m_trapSet.copyRef())
         , m_vm(vm)
     {
         static std::once_flag once;

Modified: trunk/Source/_javascript_Core/runtime/VMTraps.h (233122 => 233123)


--- trunk/Source/_javascript_Core/runtime/VMTraps.h	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/runtime/VMTraps.h	2018-06-23 09:59:04 UTC (rev 233123)
@@ -146,7 +146,7 @@
 #endif
 
     Box<Lock> m_lock;
-    RefPtr<AutomaticThreadCondition> m_trapSet;
+    Ref<AutomaticThreadCondition> m_trapSet;
     union {
         BitField m_needTrapHandling { 0 };
         BitField m_trapsBitField;

Modified: trunk/Source/_javascript_Core/wasm/WasmWorklist.cpp (233122 => 233123)


--- trunk/Source/_javascript_Core/wasm/WasmWorklist.cpp	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/wasm/WasmWorklist.cpp	2018-06-23 09:59:04 UTC (rev 233123)
@@ -58,7 +58,7 @@
 public:
     using Base = AutomaticThread;
     Thread(const AbstractLocker& locker, Worklist& work)
-        : Base(locker, work.m_lock, work.m_planEnqueued)
+        : Base(locker, work.m_lock, work.m_planEnqueued.copyRef())
         , worklist(work)
     {
 

Modified: trunk/Source/_javascript_Core/wasm/WasmWorklist.h (233122 => 233123)


--- trunk/Source/_javascript_Core/wasm/WasmWorklist.h	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/_javascript_Core/wasm/WasmWorklist.h	2018-06-23 09:59:04 UTC (rev 233123)
@@ -82,7 +82,7 @@
     }
 
     Box<Lock> m_lock;
-    RefPtr<AutomaticThreadCondition> m_planEnqueued;
+    Ref<AutomaticThreadCondition> m_planEnqueued;
     // Technically, this could overflow but that's unlikely. Even if it did, we will just compile things of the same
     // Priority it the wrong order, which isn't wrong, just suboptimal.
     Ticket m_lastGrantedTicket { 0 };

Modified: trunk/Source/WTF/ChangeLog (233122 => 233123)


--- trunk/Source/WTF/ChangeLog	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/WTF/ChangeLog	2018-06-23 09:59:04 UTC (rev 233123)
@@ -1,3 +1,26 @@
+2018-06-22  Yusuke Suzuki  <[email protected]>
+
+        [WTF] Use Ref<> for the result type of non-failing factory functions
+        https://bugs.webkit.org/show_bug.cgi?id=186920
+
+        Reviewed by Darin Adler.
+
+        Use Ref<> instead of RefPtr<> if the `create` function do not return nullptr.
+
+        * wtf/AutomaticThread.cpp:
+        (WTF::AutomaticThreadCondition::create):
+        (WTF::AutomaticThread::AutomaticThread):
+        * wtf/AutomaticThread.h:
+        * wtf/ParallelHelperPool.cpp:
+        (WTF::ParallelHelperPool::Thread::Thread):
+        * wtf/ParallelHelperPool.h:
+        * wtf/WorkerPool.cpp:
+        (WTF::WorkerPool::WorkerPool):
+        * wtf/WorkerPool.h:
+        * wtf/win/WorkQueueWin.cpp:
+        (WTF::TimerContext::create):
+        (WTF::WorkQueue::dispatchAfter):
+
 2018-06-23  Yusuke Suzuki  <[email protected]>
 
         [WTF] Add user-defined literal for ASCIILiteral

Modified: trunk/Source/WTF/wtf/AutomaticThread.cpp (233122 => 233123)


--- trunk/Source/WTF/wtf/AutomaticThread.cpp	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/WTF/wtf/AutomaticThread.cpp	2018-06-23 09:59:04 UTC (rev 233123)
@@ -33,9 +33,9 @@
 
 static const bool verbose = false;
 
-RefPtr<AutomaticThreadCondition> AutomaticThreadCondition::create()
+Ref<AutomaticThreadCondition> AutomaticThreadCondition::create()
 {
-    return adoptRef(new AutomaticThreadCondition());
+    return adoptRef(*new AutomaticThreadCondition);
 }
 
 AutomaticThreadCondition::AutomaticThreadCondition()
@@ -104,9 +104,9 @@
     return m_threads.contains(thread);
 }
 
-AutomaticThread::AutomaticThread(const AbstractLocker& locker, Box<Lock> lock, RefPtr<AutomaticThreadCondition> condition, Seconds timeout)
+AutomaticThread::AutomaticThread(const AbstractLocker& locker, Box<Lock> lock, Ref<AutomaticThreadCondition>&& condition, Seconds timeout)
     : m_lock(lock)
-    , m_condition(condition)
+    , m_condition(WTFMove(condition))
     , m_timeout(timeout)
 {
     if (verbose)

Modified: trunk/Source/WTF/wtf/AutomaticThread.h (233122 => 233123)


--- trunk/Source/WTF/wtf/AutomaticThread.h	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/WTF/wtf/AutomaticThread.h	2018-06-23 09:59:04 UTC (rev 233123)
@@ -69,7 +69,7 @@
 
 class AutomaticThreadCondition : public ThreadSafeRefCounted<AutomaticThreadCondition> {
 public:
-    static WTF_EXPORT_PRIVATE RefPtr<AutomaticThreadCondition> create();
+    static WTF_EXPORT_PRIVATE Ref<AutomaticThreadCondition> create();
     
     WTF_EXPORT_PRIVATE ~AutomaticThreadCondition();
     
@@ -131,7 +131,7 @@
 protected:
     // This logically creates the thread, but in reality the thread won't be created until someone
     // calls AutomaticThreadCondition::notifyOne() or notifyAll().
-    AutomaticThread(const AbstractLocker&, Box<Lock>, RefPtr<AutomaticThreadCondition>, Seconds timeout = 10_s);
+    AutomaticThread(const AbstractLocker&, Box<Lock>, Ref<AutomaticThreadCondition>&&, Seconds timeout = 10_s);
     
     // To understand PollResult and WorkResult, imagine that poll() and work() are being called like
     // so:
@@ -182,7 +182,7 @@
     void start(const AbstractLocker&);
     
     Box<Lock> m_lock;
-    RefPtr<AutomaticThreadCondition> m_condition;
+    Ref<AutomaticThreadCondition> m_condition;
     Seconds m_timeout;
     bool m_isRunning { true };
     bool m_isWaiting { false };

Modified: trunk/Source/WTF/wtf/ParallelHelperPool.cpp (233122 => 233123)


--- trunk/Source/WTF/wtf/ParallelHelperPool.cpp	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/WTF/wtf/ParallelHelperPool.cpp	2018-06-23 09:59:04 UTC (rev 233123)
@@ -171,7 +171,7 @@
 class ParallelHelperPool::Thread : public AutomaticThread {
 public:
     Thread(const AbstractLocker& locker, ParallelHelperPool& pool)
-        : AutomaticThread(locker, pool.m_lock, pool.m_workAvailableCondition)
+        : AutomaticThread(locker, pool.m_lock, pool.m_workAvailableCondition.copyRef())
         , m_pool(pool)
     {
     }

Modified: trunk/Source/WTF/wtf/ParallelHelperPool.h (233122 => 233123)


--- trunk/Source/WTF/wtf/ParallelHelperPool.h	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/WTF/wtf/ParallelHelperPool.h	2018-06-23 09:59:04 UTC (rev 233123)
@@ -200,7 +200,7 @@
     ParallelHelperClient* waitForClientWithTask(const AbstractLocker&);
     
     Box<Lock> m_lock; // AutomaticThread wants this in a box for safety.
-    RefPtr<AutomaticThreadCondition> m_workAvailableCondition;
+    Ref<AutomaticThreadCondition> m_workAvailableCondition;
     Condition m_workCompleteCondition;
 
     WeakRandom m_random;

Modified: trunk/Source/WTF/wtf/WorkerPool.cpp (233122 => 233123)


--- trunk/Source/WTF/wtf/WorkerPool.cpp	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/WTF/wtf/WorkerPool.cpp	2018-06-23 09:59:04 UTC (rev 233123)
@@ -34,8 +34,8 @@
 public:
     friend class WorkerPool;
 
-    Worker(const AbstractLocker& locker, WorkerPool& pool, Box<Lock> lock, RefPtr<AutomaticThreadCondition> condition, Seconds timeout)
-        : AutomaticThread(locker, lock, condition, timeout)
+    Worker(const AbstractLocker& locker, WorkerPool& pool, Box<Lock> lock, Ref<AutomaticThreadCondition>&& condition, Seconds timeout)
+        : AutomaticThread(locker, lock, WTFMove(condition), timeout)
         , m_pool(pool)
     {
     }
@@ -91,7 +91,7 @@
 {
     LockHolder locker(*m_lock);
     for (unsigned i = 0; i < numberOfWorkers; ++i)
-        m_workers.append(adoptRef(*new Worker(locker, *this, m_lock, m_condition, timeout)));
+        m_workers.append(adoptRef(*new Worker(locker, *this, m_lock, m_condition.copyRef(), timeout)));
 }
 
 WorkerPool::~WorkerPool()

Modified: trunk/Source/WTF/wtf/WorkerPool.h (233122 => 233123)


--- trunk/Source/WTF/wtf/WorkerPool.h	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/WTF/wtf/WorkerPool.h	2018-06-23 09:59:04 UTC (rev 233123)
@@ -58,7 +58,7 @@
     bool shouldSleep(const AbstractLocker&);
 
     Box<Lock> m_lock;
-    RefPtr<AutomaticThreadCondition> m_condition;
+    Ref<AutomaticThreadCondition> m_condition;
     Seconds m_timeout;
     MonotonicTime m_lastTimeoutTime { MonotonicTime::nan() };
     unsigned m_numberOfActiveWorkers { 0 };

Modified: trunk/Source/WTF/wtf/win/WorkQueueWin.cpp (233122 => 233123)


--- trunk/Source/WTF/wtf/win/WorkQueueWin.cpp	2018-06-23 08:39:34 UTC (rev 233122)
+++ trunk/Source/WTF/wtf/win/WorkQueueWin.cpp	2018-06-23 09:59:04 UTC (rev 233123)
@@ -116,7 +116,7 @@
 }
 
 struct TimerContext : public ThreadSafeRefCounted<TimerContext> {
-    static RefPtr<TimerContext> create() { return adoptRef(new TimerContext); }
+    static Ref<TimerContext> create() { return adoptRef(*new TimerContext); }
 
     Lock timerLock;
     WorkQueue* queue { nullptr };
@@ -151,7 +151,7 @@
     ASSERT(m_timerQueue);
     ref();
 
-    RefPtr<TimerContext> context = TimerContext::create();
+    Ref<TimerContext> context = TimerContext::create();
     context->queue = this;
     context->function = WTFMove(function);
 
@@ -177,7 +177,7 @@
 
         // Since our timer callback is quick, we can execute in the timer thread itself and avoid
         // an extra thread switch over to a worker thread.
-        if (!::CreateTimerQueueTimer(&context->timer, m_timerQueue, timerCallback, context.get(), clampTo<DWORD>(milliseconds), 0, WT_EXECUTEINTIMERTHREAD)) {
+        if (!::CreateTimerQueueTimer(&context->timer, m_timerQueue, timerCallback, context.ptr(), clampTo<DWORD>(milliseconds), 0, WT_EXECUTEINTIMERTHREAD)) {
             ASSERT_WITH_MESSAGE(false, "::CreateTimerQueueTimer failed with error %lu", ::GetLastError());
             return;
         }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to