Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: third_party/WebKit/Source/core/workers/WorkerBackingThread.h

Issue 1733353004: Introduce WorkerBackingThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #ifndef WorkerBackingThread_h
6 #define WorkerBackingThread_h
7
8 #include "core/CoreExport.h"
9 #include "wtf/Forward.h"
10 #include "wtf/OwnPtr.h"
11 #include "wtf/PassOwnPtr.h"
12 #include "wtf/ThreadingPrimitives.h"
13 #include <v8.h>
14
15 namespace blink {
16
17 class WebThread;
18 class WebThreadSupportingGC;
19
20 // WorkerBackingThread represents a WebThread with Oilpan and V8 potentially
21 // shared by multiple WebWorker scripts. A WebWorker needs to call attach() when
22 // attaching itself to the backing thread, and call detach() when the script
23 // no longer needs the thread.
24 // A WorkerBackingThread represents a WebThread while a WorkerThread corresponds
25 // to a web worker. There is one-to-one correspondence between WorkerThread and
26 // WorkerGlobalScope, but multiple WorkerThreads (i.e., multiple
27 // WorkerGlobalScopes) can share one WorkerBackingThread.
28 class CORE_EXPORT WorkerBackingThread final {
29 public:
30 static PassOwnPtr<WorkerBackingThread> create(const char* name) { return ado ptPtr(new WorkerBackingThread(name, false)); }
31 static PassOwnPtr<WorkerBackingThread> create(WebThread* thread) { return ad optPtr(new WorkerBackingThread(thread, false)); }
32
33 // These are needed to suppress leak reports. See
34 // https://crbug.com/590802 and https://crbug.com/v8/1428.
35 static PassOwnPtr<WorkerBackingThread> createForTest(const char* name) { ret urn adoptPtr(new WorkerBackingThread(name, true)); }
36 static PassOwnPtr<WorkerBackingThread> createForTest(WebThread* thread) { re turn adoptPtr(new WorkerBackingThread(thread, true)); }
37
38 ~WorkerBackingThread();
39
40 // attach() and detach() attaches and detaches Oilpan and V8 to / from
41 // the caller worker script, respectively. attach() and detach() increments
42 // and decrements m_workerScriptCount. attach() initializes Oilpan and V8
43 // when m_workerScriptCount is 0. detach() terminates Oilpan and V8 when
44 // m_workerScriptCount is 1. A worker script must not call any function
45 // after calling detach().
46 // They should be called from |this| thread.
47 void attach();
48 void detach();
49
50 unsigned workerScriptCount()
51 {
52 MutexLocker locker(m_mutex);
53 return m_workerScriptCount;
54 }
55
56 WebThreadSupportingGC& backingThread()
57 {
58 ASSERT(m_backingThread);
59 return *m_backingThread;
60 }
61
62 v8::Isolate* isolate() { return m_isolate; }
63
64 private:
65 WorkerBackingThread(const char* name, bool shouldCallGCOnShutdown);
66 WorkerBackingThread(WebThread*, bool shouldCallGCOnSHutdown);
67 void initialize();
68 void shutdown();
69
70 // Protects |m_workerScriptCount|.
71 Mutex m_mutex;
72 OwnPtr<WebThreadSupportingGC> m_backingThread;
73 v8::Isolate* m_isolate = nullptr;
74 unsigned m_workerScriptCount = 0;
75 bool m_isOwningThread;
76 bool m_shouldCallGCOnShutdown;
77 };
78
79 } // namespace blink
80
81 #endif // WorkerBackingThread_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698