OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/workers/WorkerBackingThread.h" | |
6 | |
7 #include "bindings/core/v8/V8Binding.h" | |
8 #include "bindings/core/v8/V8GCController.h" | |
9 #include "bindings/core/v8/V8IdleTaskRunner.h" | |
10 #include "bindings/core/v8/V8Initializer.h" | |
11 #include "bindings/core/v8/V8PerIsolateData.h" | |
12 #include "platform/RuntimeEnabledFeatures.h" | |
13 #include "platform/ThreadSafeFunctional.h" | |
14 #include "platform/WebThreadSupportingGC.h" | |
15 #include "public/platform/Platform.h" | |
16 #include "public/platform/WebTraceLocation.h" | |
17 | |
18 namespace blink { | |
19 | |
20 WorkerBackingThread::WorkerBackingThread(const char* name, bool shouldCallGCOnSh utdown) | |
21 : m_backingThread(WebThreadSupportingGC::create(name)) | |
22 , m_isOwningThread(true) | |
23 , m_shouldCallGCOnShutdown(shouldCallGCOnShutdown) | |
24 { | |
25 } | |
26 | |
27 WorkerBackingThread::WorkerBackingThread(WebThread* thread, bool shouldCallGCOnS hutdown) | |
28 : m_backingThread(WebThreadSupportingGC::createForThread(thread)) | |
29 , m_isOwningThread(false) | |
30 , m_shouldCallGCOnShutdown(shouldCallGCOnShutdown) | |
31 { | |
32 } | |
33 | |
34 WorkerBackingThread::~WorkerBackingThread() | |
35 { | |
haraken
2016/04/06 09:23:16
Shall we add:
ASSERT(m_workerScriptCount == 0);
yhirano
2016/04/07 08:12:40
Done.
| |
36 } | |
37 | |
38 void WorkerBackingThread::attach() | |
39 { | |
40 ASSERT(m_backingThread->isCurrentThread()); | |
haraken
2016/04/06 09:23:17
I think this ASSERT needs to be protected by the M
yhirano
2016/04/07 08:12:40
After WebThread::shutdown is called, you mean? The
| |
41 { | |
42 MutexLocker locker(m_mutex); | |
43 if (++m_workerScriptCount > 1) | |
44 return; | |
45 } | |
46 initialize(); | |
47 } | |
48 | |
49 void WorkerBackingThread::detach() | |
50 { | |
51 ASSERT(m_backingThread->isCurrentThread()); | |
52 { | |
53 MutexLocker locker(m_mutex); | |
54 if (--m_workerScriptCount > 0) | |
55 return; | |
56 } | |
57 shutdown(); | |
58 } | |
59 | |
60 void WorkerBackingThread::initialize() | |
61 { | |
62 ASSERT(m_backingThread->isCurrentThread()); | |
63 ASSERT(!m_isolate); | |
64 m_backingThread->initialize(); | |
65 m_isolate = V8PerIsolateData::initialize(); | |
66 V8Initializer::initializeWorker(m_isolate); | |
67 | |
68 OwnPtr<V8IsolateInterruptor> interruptor = adoptPtr(new V8IsolateInterruptor (m_isolate)); | |
69 ThreadState::current()->addInterruptor(interruptor.release()); | |
70 ThreadState::current()->registerTraceDOMWrappers(m_isolate, V8GCController:: traceDOMWrappers); | |
71 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) | |
72 V8PerIsolateData::enableIdleTasks(m_isolate, adoptPtr(new V8IdleTaskRunn er(backingThread().platformThread().scheduler()))); | |
73 if (m_isOwningThread) | |
74 Platform::current()->didStartWorkerThread(); | |
75 } | |
76 | |
77 void WorkerBackingThread::shutdown() | |
78 { | |
79 ASSERT(m_backingThread->isCurrentThread()); | |
80 if (m_isOwningThread) | |
81 Platform::current()->willStopWorkerThread(); | |
82 | |
83 V8PerIsolateData::willBeDestroyed(m_isolate); | |
84 // TODO(yhirano): Remove this when https://crbug.com/v8/1428 is fixed. | |
85 if (m_shouldCallGCOnShutdown) { | |
86 // This statement runs only in tests. | |
87 V8GCController::collectAllGarbageForTesting(m_isolate); | |
88 } | |
89 | |
90 m_backingThread->shutdown(); | |
91 | |
92 V8PerIsolateData::destroy(m_isolate); | |
haraken
2016/04/06 09:23:16
We initialize m_backingThread and then V8PerIsolat
yhirano
2016/04/07 08:12:40
Done.
| |
93 m_isolate = nullptr; | |
94 } | |
95 | |
96 } // namespace blink | |
OLD | NEW |