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

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

Issue 2041753002: Worker: Protect a running debugger task from forcible worker termination (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweak if-condition 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
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 PauseWorkerGlobalScopeOnStart 53 PauseWorkerGlobalScopeOnStart
54 }; 54 };
55 55
56 // WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism 56 // WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism
57 // can access the lower thread infrastructure via an implementation of this 57 // can access the lower thread infrastructure via an implementation of this
58 // abstract class. Multiple WorkerThreads can share one WorkerBackingThread. 58 // abstract class. Multiple WorkerThreads can share one WorkerBackingThread.
59 // See WorkerBackingThread.h for more details. 59 // See WorkerBackingThread.h for more details.
60 // 60 //
61 // 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
62 // an actual task is executed on the worker thread. 62 // an actual task is executed on the worker thread.
63 //
64 // When termination starts, (debugger) tasks on WorkerThread are handled as
65 // follows:
66 // - A running task may finish unless a forcible termination task interrupts.
67 // If the running task is for debugger, it's guaranteed to finish without
68 // any interruptions.
69 // - Queued tasks never run.
70 // - postTask() and appendDebuggerTask() reject posting new tasks.
63 class CORE_EXPORT WorkerThread { 71 class CORE_EXPORT WorkerThread {
64 public: 72 public:
65 // Represents how this thread is terminated. 73 // Represents how this thread is terminated.
66 enum class ExitCode { 74 enum class ExitCode {
67 NotTerminated, 75 NotTerminated,
68 GracefullyTerminated, 76 GracefullyTerminated,
69 SyncForciblyTerminated, 77 SyncForciblyTerminated,
70 AsyncForciblyTerminated, 78 AsyncForciblyTerminated,
71 }; 79 };
72 80
(...skipping 23 matching lines...) Expand all
96 { 104 {
97 RELEASE_ASSERT(m_workerLoaderProxy); 105 RELEASE_ASSERT(m_workerLoaderProxy);
98 return m_workerLoaderProxy.get(); 106 return m_workerLoaderProxy.get();
99 } 107 }
100 108
101 WorkerReportingProxy& workerReportingProxy() const { return m_workerReportin gProxy; } 109 WorkerReportingProxy& workerReportingProxy() const { return m_workerReportin gProxy; }
102 110
103 void postTask(const WebTraceLocation&, std::unique_ptr<ExecutionContextTask> ); 111 void postTask(const WebTraceLocation&, std::unique_ptr<ExecutionContextTask> );
104 void appendDebuggerTask(std::unique_ptr<CrossThreadClosure>); 112 void appendDebuggerTask(std::unique_ptr<CrossThreadClosure>);
105 113
106 // Runs only debugger tasks while paused in debugger, called on the worker 114 // Runs only debugger tasks while paused in debugger.
107 // thread. 115 void startRunningDebuggerTasksOnPauseOnWorkerThread();
108 void startRunningDebuggerTasksOnPause(); 116 void stopRunningDebuggerTasksOnPauseOnWorkerThread();
109 void stopRunningDebuggerTasksOnPause();
110 bool isRunningDebuggerTasksOnPause() const { return m_pausedInDebugger; }
111 117
112 // Can be called only on the worker thread, WorkerGlobalScope is not thread 118 // Can be called only on the worker thread, WorkerGlobalScope is not thread
113 // safe. 119 // safe.
114 WorkerGlobalScope* workerGlobalScope(); 120 WorkerGlobalScope* workerGlobalScope();
115 121
116 // Returns true once one of the terminate* methods is called. 122 // Returns true once one of the terminate* methods is called.
117 bool terminated(); 123 bool terminated();
118 124
119 // Number of active worker threads. 125 // Number of active worker threads.
120 static unsigned workerThreadCount(); 126 static unsigned workerThreadCount();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 159
154 std::unique_ptr<CrossThreadClosure> createWorkerThreadTask(std::unique_ptr<E xecutionContextTask>, bool isInstrumented); 160 std::unique_ptr<CrossThreadClosure> createWorkerThreadTask(std::unique_ptr<E xecutionContextTask>, bool isInstrumented);
155 161
156 void terminateInternal(TerminationMode); 162 void terminateInternal(TerminationMode);
157 void forciblyTerminateExecution(); 163 void forciblyTerminateExecution();
158 164
159 void initializeOnWorkerThread(PassOwnPtr<WorkerThreadStartupData>); 165 void initializeOnWorkerThread(PassOwnPtr<WorkerThreadStartupData>);
160 void prepareForShutdownOnWorkerThread(); 166 void prepareForShutdownOnWorkerThread();
161 void performShutdownOnWorkerThread(); 167 void performShutdownOnWorkerThread();
162 void performTaskOnWorkerThread(std::unique_ptr<ExecutionContextTask>, bool i sInstrumented); 168 void performTaskOnWorkerThread(std::unique_ptr<ExecutionContextTask>, bool i sInstrumented);
163 void runDebuggerTaskOnWorkerThread(std::unique_ptr<CrossThreadClosure>); 169 void performDebuggerTaskOnWorkerThread(std::unique_ptr<CrossThreadClosure>);
164 void runDebuggerTaskDontWaitOnWorkerThread(); 170 void performDebuggerTaskDontWaitOnWorkerThread();
165 171
166 void setForceTerminationDelayInMsForTesting(long long forceTerminationDelayI nMs) { m_forceTerminationDelayInMs = forceTerminationDelayInMs; } 172 void setForceTerminationDelayInMsForTesting(long long forceTerminationDelayI nMs) { m_forceTerminationDelayInMs = forceTerminationDelayInMs; }
167 173
168 bool m_started = false; 174 bool m_started = false;
169 bool m_terminated = false; 175 bool m_terminated = false;
170 bool m_readyToShutdown = false; 176 bool m_readyToShutdown = false;
171 bool m_pausedInDebugger = false; 177 bool m_pausedInDebugger = false;
172 bool m_runningDebuggerTask = false; 178 bool m_runningDebuggerTask = false;
173 ExitCode m_exitCode = ExitCode::NotTerminated; 179 ExitCode m_exitCode = ExitCode::NotTerminated;
174 180
(...skipping 19 matching lines...) Expand all
194 OwnPtr<WaitableEvent> m_shutdownEvent; 200 OwnPtr<WaitableEvent> m_shutdownEvent;
195 201
196 // Scheduled when termination starts with TerminationMode::Force, and 202 // Scheduled when termination starts with TerminationMode::Force, and
197 // cancelled when the worker thread is gracefully shut down. 203 // cancelled when the worker thread is gracefully shut down.
198 OwnPtr<ForceTerminationTask> m_scheduledForceTerminationTask; 204 OwnPtr<ForceTerminationTask> m_scheduledForceTerminationTask;
199 }; 205 };
200 206
201 } // namespace blink 207 } // namespace blink
202 208
203 #endif // WorkerThread_h 209 #endif // WorkerThread_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698