| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/WebThreadSupportingGC.h" | 5 #include "platform/WebThreadSupportingGC.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include "platform/heap/SafePoint.h" | 8 #include "platform/heap/SafePoint.h" |
| 9 #include "platform/scheduler/child/web_scheduler.h" | 9 #include "platform/scheduler/child/web_scheduler.h" |
| 10 #include "platform/wtf/PtrUtil.h" | 10 #include "platform/wtf/PtrUtil.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 WebThread* thread) | 26 WebThread* thread) |
| 27 : thread_(thread) { | 27 : thread_(thread) { |
| 28 DCHECK(!name || !thread); | 28 DCHECK(!name || !thread); |
| 29 #if DCHECK_IS_ON() | 29 #if DCHECK_IS_ON() |
| 30 // We call this regardless of whether an existing thread is given or not, | 30 // We call this regardless of whether an existing thread is given or not, |
| 31 // as it means that blink is going to run with more than one thread. | 31 // as it means that blink is going to run with more than one thread. |
| 32 WTF::WillCreateThread(); | 32 WTF::WillCreateThread(); |
| 33 #endif | 33 #endif |
| 34 if (!thread_) { | 34 if (!thread_) { |
| 35 // If |thread| is not given, create a new one and own it. | 35 // If |thread| is not given, create a new one and own it. |
| 36 owning_thread_ = WTF::WrapUnique(Platform::Current()->CreateThread(name)); | 36 owning_thread_ = Platform::Current()->CreateThread(name); |
| 37 thread_ = owning_thread_.get(); | 37 thread_ = owning_thread_.get(); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 WebThreadSupportingGC::~WebThreadSupportingGC() { | 41 WebThreadSupportingGC::~WebThreadSupportingGC() { |
| 42 // WebThread's destructor blocks until all the tasks are processed. | 42 // WebThread's destructor blocks until all the tasks are processed. |
| 43 owning_thread_.reset(); | 43 owning_thread_.reset(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void WebThreadSupportingGC::Initialize() { | 46 void WebThreadSupportingGC::Initialize() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 | 57 |
| 58 // Shutdown the thread (via its scheduler) only when the thread is created | 58 // Shutdown the thread (via its scheduler) only when the thread is created |
| 59 // and is owned by this instance. | 59 // and is owned by this instance. |
| 60 if (owning_thread_) | 60 if (owning_thread_) |
| 61 owning_thread_->Scheduler()->Shutdown(); | 61 owning_thread_->Scheduler()->Shutdown(); |
| 62 | 62 |
| 63 ThreadState::DetachCurrentThread(); | 63 ThreadState::DetachCurrentThread(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 } // namespace blink | 66 } // namespace blink |
| OLD | NEW |