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

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

Issue 956333002: Refactor TimeBase to post tasks. Workers to use real Idle tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased Created 5 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
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 29 matching lines...) Expand all
40 #include "wtf/PassRefPtr.h" 40 #include "wtf/PassRefPtr.h"
41 #include "wtf/RefCounted.h" 41 #include "wtf/RefCounted.h"
42 #include <v8.h> 42 #include <v8.h>
43 43
44 namespace blink { 44 namespace blink {
45 45
46 class WebWaitableEvent; 46 class WebWaitableEvent;
47 class WorkerGlobalScope; 47 class WorkerGlobalScope;
48 class WorkerInspectorController; 48 class WorkerInspectorController;
49 class WorkerReportingProxy; 49 class WorkerReportingProxy;
50 class WorkerSharedTimer;
51 class WorkerThreadShutdownFinishTask; 50 class WorkerThreadShutdownFinishTask;
52 class WorkerThreadStartupData; 51 class WorkerThreadStartupData;
53 class WorkerThreadTask; 52 class WorkerThreadTask;
54 53
55 enum WorkerThreadStartMode { 54 enum WorkerThreadStartMode {
56 DontPauseWorkerGlobalScopeOnStart, 55 DontPauseWorkerGlobalScopeOnStart,
57 PauseWorkerGlobalScopeOnStart 56 PauseWorkerGlobalScopeOnStart
58 }; 57 };
59 58
60 class CORE_EXPORT WorkerThread : public RefCounted<WorkerThread> { 59 class CORE_EXPORT WorkerThread : public RefCounted<WorkerThread> {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Factory method for creating a new worker context for the thread. 114 // Factory method for creating a new worker context for the thread.
116 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0; 115 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0;
117 116
118 virtual void postInitialize() { } 117 virtual void postInitialize() { }
119 118
120 virtual v8::Isolate* initializeIsolate(); 119 virtual v8::Isolate* initializeIsolate();
121 virtual void willDestroyIsolate(); 120 virtual void willDestroyIsolate();
122 virtual void destroyIsolate(); 121 virtual void destroyIsolate();
123 virtual void terminateV8Execution(); 122 virtual void terminateV8Execution();
124 123
124 // This is protected virtual for testing.
125 virtual bool doIdleGc(double deadlineSeconds);
126
127 WebThreadSupportingGC* threadForTesting() const
128 {
129 return m_thread.get();
130 }
131
132 void setMinQuietPeriodBeforeDoingIdleGcForTesting(long long minQuietPeriodBe foreDoingIdleGc)
Sami 2015/04/09 10:52:29 For better or worse, "double seconds" is the prefe
alex clarke (OOO till 29th) 2015/04/10 15:29:38 Acknowledged.
133 {
134 m_minQuietPeriodMsBeforeDoingIdleGc = minQuietPeriodBeforeDoingIdleGc;
135 }
136
125 private: 137 private:
126 friend class WorkerSharedTimer; 138 friend class WorkerThreadIdleTask;
127 friend class WorkerThreadShutdownFinishTask; 139 friend class WorkerThreadShutdownFinishTask;
140 friend class WorkerThreadWaitUntilIdleTask;
141 friend class WorkerThreadWakeupIdleTask;
128 142
129 void stopInShutdownSequence(); 143 void stopInShutdownSequence();
130 void stopInternal(); 144 void stopInternal();
131 145
132 void initialize(); 146 void initialize();
133 void cleanup(); 147 void cleanup();
134 void idleHandler(); 148 void dontStartIdleTaskYet();
Sami 2015/04/09 10:52:29 Okay, I think I agree that it's probably better no
alex clarke (OOO till 29th) 2015/04/10 15:29:37 Acknowledged.
149 void maybeStartIdleTask();
150 void idleTask(double deadlineSeconds);
135 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs); 151 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs);
136 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs); 152 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs);
137 153
138 bool m_terminated; 154 bool m_terminated;
139 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue; 155 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue;
140 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; 156 OwnPtr<WebThread::TaskObserver> m_microtaskRunner;
141 157
142 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; 158 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy;
143 WorkerReportingProxy& m_workerReportingProxy; 159 WorkerReportingProxy& m_workerReportingProxy;
144 160
145 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle r; 161 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle r;
146 Mutex m_workerInspectorControllerMutex; 162 Mutex m_workerInspectorControllerMutex;
147 163
148 Mutex m_threadCreationMutex; 164 Mutex m_threadCreationMutex;
149 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; 165 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope;
150 OwnPtr<WorkerThreadStartupData> m_startupData; 166 OwnPtr<WorkerThreadStartupData> m_startupData;
151 167
152 v8::Isolate* m_isolate; 168 v8::Isolate* m_isolate;
153 OwnPtr<V8IsolateInterruptor> m_interruptor; 169 OwnPtr<V8IsolateInterruptor> m_interruptor;
154 170
155 // Used to signal thread shutdown. 171 // Used to signal thread shutdown.
156 OwnPtr<WebWaitableEvent> m_shutdownEvent; 172 OwnPtr<WebWaitableEvent> m_shutdownEvent;
157 173
158 // Used to signal thread termination. 174 // Used to signal thread termination.
159 OwnPtr<WebWaitableEvent> m_terminationEvent; 175 OwnPtr<WebWaitableEvent> m_terminationEvent;
160 176
177 long long m_minQuietPeriodMsBeforeDoingIdleGc;
178 bool m_dontStartIdleTaskYet;
179
161 // FIXME: This has to be last because of crbug.com/401397 - the 180 // FIXME: This has to be last because of crbug.com/401397 - the
162 // WorkerThread might get deleted before it had a chance to properly 181 // WorkerThread might get deleted before it had a chance to properly
163 // shut down. By deleting the WebThread first, we can guarantee that 182 // shut down. By deleting the WebThread first, we can guarantee that
164 // no pending tasks on the thread might want to access any of the other 183 // no pending tasks on the thread might want to access any of the other
165 // members during the WorkerThread's destruction. 184 // members during the WorkerThread's destruction.
166 OwnPtr<WebThreadSupportingGC> m_thread; 185 OwnPtr<WebThreadSupportingGC> m_thread;
167 }; 186 };
168 187
169 } // namespace blink 188 } // namespace blink
170 189
171 #endif // WorkerThread_h 190 #endif // WorkerThread_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698