OLD | NEW |
---|---|
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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 ASSERT(context->isWorkerGlobalScope()); | 249 ASSERT(context->isWorkerGlobalScope()); |
250 m_thread->runDebuggerTask(WorkerThread::DontWaitForMessage); | 250 m_thread->runDebuggerTask(WorkerThread::DontWaitForMessage); |
251 } | 251 } |
252 | 252 |
253 private: | 253 private: |
254 explicit RunDebuggerQueueTask(WorkerThread* thread) : m_thread(thread) { } | 254 explicit RunDebuggerQueueTask(WorkerThread* thread) : m_thread(thread) { } |
255 | 255 |
256 WorkerThread* m_thread; | 256 WorkerThread* m_thread; |
257 }; | 257 }; |
258 | 258 |
259 WorkerThread::WorkerThread(const char* threadName, PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, PassOwnPtr<Worke rThreadStartupData> startupData) | 259 WorkerThread::WorkerThread(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, Work erReportingProxy& workerReportingProxy, PassOwnPtr<WorkerThreadStartupData> star tupData) |
260 : m_threadName(threadName) | 260 : m_terminated(false) |
261 , m_terminated(false) | |
262 , m_workerLoaderProxy(workerLoaderProxy) | 261 , m_workerLoaderProxy(workerLoaderProxy) |
263 , m_workerReportingProxy(workerReportingProxy) | 262 , m_workerReportingProxy(workerReportingProxy) |
264 , m_startupData(startupData) | 263 , m_startupData(startupData) |
265 , m_isolate(nullptr) | 264 , m_isolate(nullptr) |
266 , m_shutdownEvent(adoptPtr(blink::Platform::current()->createWaitableEvent() )) | 265 , m_shutdownEvent(adoptPtr(blink::Platform::current()->createWaitableEvent() )) |
267 , m_terminationEvent(adoptPtr(blink::Platform::current()->createWaitableEven t())) | 266 , m_terminationEvent(adoptPtr(blink::Platform::current()->createWaitableEven t())) |
267 , m_thread(nullptr) | |
268 { | 268 { |
269 MutexLocker lock(threadSetMutex()); | 269 MutexLocker lock(threadSetMutex()); |
270 workerThreads().add(this); | 270 workerThreads().add(this); |
271 } | 271 } |
272 | 272 |
273 WorkerThread::~WorkerThread() | 273 WorkerThread::~WorkerThread() |
274 { | 274 { |
275 MutexLocker lock(threadSetMutex()); | 275 MutexLocker lock(threadSetMutex()); |
276 ASSERT(workerThreads().contains(this)); | 276 ASSERT(workerThreads().contains(this)); |
277 workerThreads().remove(this); | 277 workerThreads().remove(this); |
278 } | 278 } |
279 | 279 |
280 void WorkerThread::start() | 280 void WorkerThread::start() |
281 { | 281 { |
282 if (m_thread) | 282 if (m_thread) |
283 return; | 283 return; |
284 | 284 |
285 m_thread = createWebThreadSupportingGC(); | 285 m_thread = webThreadSupportingGC(); |
286 m_thread->postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::initial ize, AllowCrossThreadAccess(this)))); | 286 m_thread->postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::initial ize, AllowCrossThreadAccess(this)))); |
kinuko
2015/04/30 02:30:07
Can we have a separate flag (like m_started) and j
sadrul
2015/04/30 05:27:40
Done.
| |
287 } | 287 } |
288 | 288 |
289 void WorkerThread::interruptAndDispatchInspectorCommands() | 289 void WorkerThread::interruptAndDispatchInspectorCommands() |
290 { | 290 { |
291 MutexLocker locker(m_workerInspectorControllerMutex); | 291 MutexLocker locker(m_workerInspectorControllerMutex); |
292 if (m_workerInspectorController) | 292 if (m_workerInspectorController) |
293 m_workerInspectorController->interruptAndDispatchInspectorCommands(); | 293 m_workerInspectorController->interruptAndDispatchInspectorCommands(); |
294 } | 294 } |
295 | 295 |
296 PlatformThreadId WorkerThread::platformThreadId() const | 296 PlatformThreadId WorkerThread::platformThreadId() const |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 OwnPtr<CachedMetadataHandler> handler(workerGlobalScope()->createWorkerScrip tCachedMetadataHandler(scriptURL, cachedMetaData.get())); | 345 OwnPtr<CachedMetadataHandler> handler(workerGlobalScope()->createWorkerScrip tCachedMetadataHandler(scriptURL, cachedMetaData.get())); |
346 bool success = script->evaluate(ScriptSourceCode(sourceCode, scriptURL), nul lptr, handler.get(), v8CacheOptions); | 346 bool success = script->evaluate(ScriptSourceCode(sourceCode, scriptURL), nul lptr, handler.get(), v8CacheOptions); |
347 m_workerGlobalScope->didEvaluateWorkerScript(); | 347 m_workerGlobalScope->didEvaluateWorkerScript(); |
348 m_workerReportingProxy.didEvaluateWorkerScript(success); | 348 m_workerReportingProxy.didEvaluateWorkerScript(success); |
349 | 349 |
350 postInitialize(); | 350 postInitialize(); |
351 | 351 |
352 postDelayedTask(FROM_HERE, createSameThreadTask(&WorkerThread::idleHandler, this), kShortIdleHandlerDelayMs); | 352 postDelayedTask(FROM_HERE, createSameThreadTask(&WorkerThread::idleHandler, this), kShortIdleHandlerDelayMs); |
353 } | 353 } |
354 | 354 |
355 PassOwnPtr<WebThreadSupportingGC> WorkerThread::createWebThreadSupportingGC() | |
356 { | |
357 return WebThreadSupportingGC::create(m_threadName); | |
358 } | |
359 | |
360 void WorkerThread::cleanup() | 355 void WorkerThread::cleanup() |
361 { | 356 { |
362 // This should be called before we start the shutdown procedure. | 357 // This should be called before we start the shutdown procedure. |
363 workerReportingProxy().willDestroyWorkerGlobalScope(); | 358 workerReportingProxy().willDestroyWorkerGlobalScope(); |
364 | 359 |
365 // The below assignment will destroy the context, which will in turn notify messaging proxy. | 360 // The below assignment will destroy the context, which will in turn notify messaging proxy. |
366 // We cannot let any objects survive past thread exit, because no other thre ad will run GC or otherwise destroy them. | 361 // We cannot let any objects survive past thread exit, because no other thre ad will run GC or otherwise destroy them. |
367 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out. | 362 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out. |
368 #if !ENABLE(OILPAN) | 363 #if !ENABLE(OILPAN) |
369 ASSERT(m_workerGlobalScope->hasOneRef()); | 364 ASSERT(m_workerGlobalScope->hasOneRef()); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 606 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
612 } | 607 } |
613 | 608 |
614 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) | 609 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) |
615 { | 610 { |
616 MutexLocker locker(m_workerInspectorControllerMutex); | 611 MutexLocker locker(m_workerInspectorControllerMutex); |
617 m_workerInspectorController = workerInspectorController; | 612 m_workerInspectorController = workerInspectorController; |
618 } | 613 } |
619 | 614 |
620 } // namespace blink | 615 } // namespace blink |
OLD | NEW |