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

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

Issue 2006273003: Worker: Make WorkerMicrotaskRunner a private inner class of WorkerThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/workers/WorkerThread.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 27 matching lines...) Expand all
38 #include "wtf/PassRefPtr.h" 38 #include "wtf/PassRefPtr.h"
39 #include <v8.h> 39 #include <v8.h>
40 40
41 namespace blink { 41 namespace blink {
42 42
43 class InspectorTaskRunner; 43 class InspectorTaskRunner;
44 class WaitableEvent; 44 class WaitableEvent;
45 class WorkerBackingThread; 45 class WorkerBackingThread;
46 class WorkerGlobalScope; 46 class WorkerGlobalScope;
47 class WorkerInspectorController; 47 class WorkerInspectorController;
48 class WorkerMicrotaskRunner;
49 class WorkerReportingProxy; 48 class WorkerReportingProxy;
50 class WorkerThreadStartupData; 49 class WorkerThreadStartupData;
51 50
52 enum WorkerThreadStartMode { 51 enum WorkerThreadStartMode {
53 DontPauseWorkerGlobalScopeOnStart, 52 DontPauseWorkerGlobalScopeOnStart,
54 PauseWorkerGlobalScopeOnStart 53 PauseWorkerGlobalScopeOnStart
55 }; 54 };
56 55
57 // WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism 56 // WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism
58 // can access the lower thread infrastructure via an implementation of this 57 // can access the lower thread infrastructure via an implementation of this
59 // abstract class. Multiple WorkerThreads can share one WorkerBackingThread. 58 // abstract class. Multiple WorkerThreads can share one WorkerBackingThread.
60 // See WorkerBackingThread.h for more details. 59 // See WorkerBackingThread.h for more details.
61 // 60 //
62 // WorkerThread start and termination must be initiated on the main thread and 61 // WorkerThread start and termination must be initiated on the main thread and
63 // an actual task is executed on the worker thread. 62 // an actual task is executed on the worker thread.
64 class CORE_EXPORT WorkerThread { 63 class CORE_EXPORT WorkerThread {
65 public: 64 public:
66 virtual ~WorkerThread(); 65 virtual ~WorkerThread();
67 66
68 // Called on the main thread. 67 // Called on the main thread.
69 void start(PassOwnPtr<WorkerThreadStartupData>); 68 void start(PassOwnPtr<WorkerThreadStartupData>);
70 void terminate(); 69 void terminate();
71 70
72 // Called in shutdown sequence on the main thread. Internally calls 71 // Called in shutdown sequence on the main thread. Internally calls
73 // terminate() and wait (by *blocking* the calling thread) until the 72 // terminate() and wait (by *blocking* the calling thread) until the
74 // worker(s) is/are shut down. 73 // worker(s) is/are shut down.
75 void terminateAndWait(); 74 void terminateAndWait();
76 static void terminateAndWaitForAllWorkers(); 75 static void terminateAndWaitForAllWorkers();
77 76
78 // Called on the worker thread. Disposes |m_workerGlobalScope|.
79 void prepareForShutdown();
80
81 virtual WorkerBackingThread& workerBackingThread() = 0; 77 virtual WorkerBackingThread& workerBackingThread() = 0;
82 virtual bool shouldAttachThreadDebugger() const { return true; } 78 virtual bool shouldAttachThreadDebugger() const { return true; }
83 v8::Isolate* isolate(); 79 v8::Isolate* isolate();
84 80
85 // Can be used to wait for this worker thread to terminate. 81 // Can be used to wait for this worker thread to terminate.
86 // (This is signaled on the main thread, so it's assumed to be waited on 82 // (This is signaled on the main thread, so it's assumed to be waited on
87 // the worker context thread) 83 // the worker context thread)
88 WaitableEvent* terminationEvent() { return m_terminationEvent.get(); } 84 WaitableEvent* terminationEvent() { return m_terminationEvent.get(); }
89 85
90 bool isCurrentThread(); 86 bool isCurrentThread();
(...skipping 30 matching lines...) Expand all
121 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); 117 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&);
122 118
123 // Factory method for creating a new worker context for the thread. 119 // Factory method for creating a new worker context for the thread.
124 // Called on the worker thread. 120 // Called on the worker thread.
125 virtual WorkerGlobalScope* createWorkerGlobalScope(PassOwnPtr<WorkerThreadSt artupData>) = 0; 121 virtual WorkerGlobalScope* createWorkerGlobalScope(PassOwnPtr<WorkerThreadSt artupData>) = 0;
126 122
127 // Called on the worker thread. 123 // Called on the worker thread.
128 virtual void postInitialize() { } 124 virtual void postInitialize() { }
129 125
130 private: 126 private:
127 class WorkerMicrotaskRunner;
128
131 std::unique_ptr<CrossThreadClosure> createWorkerThreadTask(std::unique_ptr<E xecutionContextTask>, bool isInstrumented); 129 std::unique_ptr<CrossThreadClosure> createWorkerThreadTask(std::unique_ptr<E xecutionContextTask>, bool isInstrumented);
132 130
133 // Called on the worker thread. 131 // Called on the worker thread.
134 void initialize(PassOwnPtr<WorkerThreadStartupData>); 132 void initialize(PassOwnPtr<WorkerThreadStartupData>);
135 void performTask(std::unique_ptr<ExecutionContextTask>, bool isInstrumented) ; 133 void performTask(std::unique_ptr<ExecutionContextTask>, bool isInstrumented) ;
136 void performShutdownTask(); 134 void prepareForShutdown();
135 void performShutdown();
137 void runDebuggerTask(std::unique_ptr<CrossThreadClosure>); 136 void runDebuggerTask(std::unique_ptr<CrossThreadClosure>);
138 void runDebuggerTaskDontWait(); 137 void runDebuggerTaskDontWait();
139 138
140 bool m_started = false; 139 bool m_started = false;
141 bool m_terminated = false; 140 bool m_terminated = false;
142 bool m_readyToShutdown = false; 141 bool m_readyToShutdown = false;
143 bool m_pausedInDebugger = false; 142 bool m_pausedInDebugger = false;
144 bool m_runningDebuggerTask = false; 143 bool m_runningDebuggerTask = false;
145 bool m_shouldTerminateV8Execution = false; 144 bool m_shouldTerminateV8Execution = false;
146 145
147 OwnPtr<InspectorTaskRunner> m_inspectorTaskRunner; 146 OwnPtr<InspectorTaskRunner> m_inspectorTaskRunner;
148 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; 147 OwnPtr<WorkerMicrotaskRunner> m_microtaskRunner;
149 148
150 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; 149 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy;
151 WorkerReportingProxy& m_workerReportingProxy; 150 WorkerReportingProxy& m_workerReportingProxy;
152 151
153 // This lock protects |m_workerGlobalScope|, |m_terminated|, 152 // This lock protects |m_workerGlobalScope|, |m_terminated|,
154 // |m_readyToShutdown|, |m_runningDebuggerTask|, 153 // |m_readyToShutdown|, |m_runningDebuggerTask|,
155 // |m_shouldTerminateV8Execution| and |m_microtaskRunner|. 154 // |m_shouldTerminateV8Execution| and |m_microtaskRunner|.
156 Mutex m_threadStateMutex; 155 Mutex m_threadStateMutex;
157 156
158 Persistent<WorkerGlobalScope> m_workerGlobalScope; 157 Persistent<WorkerGlobalScope> m_workerGlobalScope;
159 158
160 // Signaled when the thread starts termination on the main thread. 159 // Signaled when the thread starts termination on the main thread.
161 OwnPtr<WaitableEvent> m_terminationEvent; 160 OwnPtr<WaitableEvent> m_terminationEvent;
162 161
163 // Signaled when the thread completes termination on the worker thread. 162 // Signaled when the thread completes termination on the worker thread.
164 OwnPtr<WaitableEvent> m_shutdownEvent; 163 OwnPtr<WaitableEvent> m_shutdownEvent;
165 }; 164 };
166 165
167 } // namespace blink 166 } // namespace blink
168 167
169 #endif // WorkerThread_h 168 #endif // WorkerThread_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/workers/WorkerThread.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698