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

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

Issue 1100413004: workers: Move ownership of WebThread from WorkerThread (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 7 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 | Annotate | Revision Log
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 class WorkerSharedTimer; 50 class WorkerSharedTimer;
51 class WorkerThreadShutdownFinishTask; 51 class WorkerThreadShutdownFinishTask;
52 class WorkerThreadStartupData; 52 class WorkerThreadStartupData;
53 class WorkerThreadTask; 53 class WorkerThreadTask;
54 54
55 enum WorkerThreadStartMode { 55 enum WorkerThreadStartMode {
56 DontPauseWorkerGlobalScopeOnStart, 56 DontPauseWorkerGlobalScopeOnStart,
57 PauseWorkerGlobalScopeOnStart 57 PauseWorkerGlobalScopeOnStart
58 }; 58 };
59 59
60 class CORE_EXPORT WorkerThread : public RefCounted<WorkerThread> { 60 class CORE_EXPORT WorkerThread : public RefCounted<WorkerThread> {
kinuko 2015/04/30 02:30:07 TODO for renaming this?
sadrul 2015/04/30 05:27:40 Done.
61 public: 61 public:
62 virtual ~WorkerThread(); 62 virtual ~WorkerThread();
63 63
64 virtual void start(); 64 virtual void start();
65 virtual void stop(); 65 virtual void stop();
66 66
67 virtual PassOwnPtr<WebThreadSupportingGC> createWebThreadSupportingGC(); 67 virtual WebThreadSupportingGC* webThreadSupportingGC() = 0;
kinuko 2015/04/30 02:30:07 Can you give a brief explanation? It'd be nice to
sadrul 2015/04/30 05:27:40 Done.
68 virtual void didStartRunLoop(); 68 virtual void didStartRunLoop();
69 virtual void didStopRunLoop(); 69 virtual void didStopRunLoop();
70 70
71 v8::Isolate* isolate() const { return m_isolate; } 71 v8::Isolate* isolate() const { return m_isolate; }
72 72
73 // Can be used to wait for this worker thread to shut down. 73 // Can be used to wait for this worker thread to shut down.
74 // (This is signalled on the main thread, so it's assumed to be waited on th e worker context thread) 74 // (This is signalled on the main thread, so it's assumed to be waited on th e worker context thread)
75 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } 75 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); }
76 76
77 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } 77 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); }
(...skipping 25 matching lines...) Expand all
103 103
104 // Number of active worker threads. 104 // Number of active worker threads.
105 static unsigned workerThreadCount(); 105 static unsigned workerThreadCount();
106 106
107 PlatformThreadId platformThreadId() const; 107 PlatformThreadId platformThreadId() const;
108 108
109 void interruptAndDispatchInspectorCommands(); 109 void interruptAndDispatchInspectorCommands();
110 void setWorkerInspectorController(WorkerInspectorController*); 110 void setWorkerInspectorController(WorkerInspectorController*);
111 111
112 protected: 112 protected:
113 WorkerThread(const char* threadName, PassRefPtr<WorkerLoaderProxy>, WorkerRe portingProxy&, PassOwnPtr<WorkerThreadStartupData>); 113 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&, PassOwnPt r<WorkerThreadStartupData>);
114 114
115 // Factory method for creating a new worker context for the thread. 115 // Factory method for creating a new worker context for the thread.
116 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0; 116 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0;
117 117
118 virtual void postInitialize() { } 118 virtual void postInitialize() { }
119 119
120 virtual v8::Isolate* initializeIsolate(); 120 virtual v8::Isolate* initializeIsolate();
121 virtual void willDestroyIsolate(); 121 virtual void willDestroyIsolate();
122 virtual void destroyIsolate(); 122 virtual void destroyIsolate();
123 virtual void terminateV8Execution(); 123 virtual void terminateV8Execution();
124 124
125 private: 125 private:
126 friend class WorkerSharedTimer; 126 friend class WorkerSharedTimer;
127 friend class WorkerThreadShutdownFinishTask; 127 friend class WorkerThreadShutdownFinishTask;
128 128
129 void stopInShutdownSequence(); 129 void stopInShutdownSequence();
130 void stopInternal(); 130 void stopInternal();
131 131
132 void initialize(); 132 void initialize();
133 void cleanup(); 133 void cleanup();
134 void idleHandler(); 134 void idleHandler();
135 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs); 135 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs);
136 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs); 136 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs);
137 137
138 const char* m_threadName;
139 bool m_terminated; 138 bool m_terminated;
140 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue; 139 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue;
141 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; 140 OwnPtr<WebThread::TaskObserver> m_microtaskRunner;
142 141
143 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; 142 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy;
144 WorkerReportingProxy& m_workerReportingProxy; 143 WorkerReportingProxy& m_workerReportingProxy;
145 144
146 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle r; 145 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle r;
147 Mutex m_workerInspectorControllerMutex; 146 Mutex m_workerInspectorControllerMutex;
148 147
149 Mutex m_threadCreationMutex; 148 Mutex m_threadCreationMutex;
150 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; 149 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope;
151 OwnPtr<WorkerThreadStartupData> m_startupData; 150 OwnPtr<WorkerThreadStartupData> m_startupData;
152 151
153 v8::Isolate* m_isolate; 152 v8::Isolate* m_isolate;
154 OwnPtr<V8IsolateInterruptor> m_interruptor; 153 OwnPtr<V8IsolateInterruptor> m_interruptor;
155 154
156 // Used to signal thread shutdown. 155 // Used to signal thread shutdown.
157 OwnPtr<WebWaitableEvent> m_shutdownEvent; 156 OwnPtr<WebWaitableEvent> m_shutdownEvent;
158 157
159 // Used to signal thread termination. 158 // Used to signal thread termination.
160 OwnPtr<WebWaitableEvent> m_terminationEvent; 159 OwnPtr<WebWaitableEvent> m_terminationEvent;
161 160
162 // FIXME: This has to be last because of crbug.com/401397 - the 161 WebThreadSupportingGC* m_thread;
163 // WorkerThread might get deleted before it had a chance to properly
164 // shut down. By deleting the WebThread first, we can guarantee that
165 // no pending tasks on the thread might want to access any of the other
166 // members during the WorkerThread's destruction.
167 OwnPtr<WebThreadSupportingGC> m_thread;
168 }; 162 };
169 163
170 } // namespace blink 164 } // namespace blink
171 165
172 #endif // WorkerThread_h 166 #endif // WorkerThread_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698