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 21 matching lines...) Expand all Loading... |
32 #include "core/inspector/InspectorInstrumentation.h" | 32 #include "core/inspector/InspectorInstrumentation.h" |
33 #include "core/workers/DedicatedWorkerGlobalScope.h" | 33 #include "core/workers/DedicatedWorkerGlobalScope.h" |
34 #include "core/workers/WorkerClients.h" | 34 #include "core/workers/WorkerClients.h" |
35 #include "core/workers/WorkerReportingProxy.h" | 35 #include "core/workers/WorkerReportingProxy.h" |
36 #include "core/workers/WorkerThreadStartupData.h" | 36 #include "core/workers/WorkerThreadStartupData.h" |
37 #include "modules/webdatabase/DatabaseManager.h" | 37 #include "modules/webdatabase/DatabaseManager.h" |
38 #include "modules/webdatabase/DatabaseTask.h" | 38 #include "modules/webdatabase/DatabaseTask.h" |
39 #include "platform/PlatformThreadData.h" | 39 #include "platform/PlatformThreadData.h" |
40 #include "platform/weborigin/KURL.h" | 40 #include "platform/weborigin/KURL.h" |
41 #include "public/platform/Platform.h" | 41 #include "public/platform/Platform.h" |
| 42 #include "public/platform/WebWaitableEvent.h" |
42 #include "public/platform/WebWorkerRunLoop.h" | 43 #include "public/platform/WebWorkerRunLoop.h" |
43 #include "wtf/Noncopyable.h" | 44 #include "wtf/Noncopyable.h" |
44 #include "wtf/text/WTFString.h" | 45 #include "wtf/text/WTFString.h" |
45 | 46 |
46 #include <utility> | 47 #include <utility> |
47 | 48 |
48 namespace WebCore { | 49 namespace WebCore { |
49 | 50 |
50 static Mutex& threadSetMutex() | 51 static Mutex& threadSetMutex() |
51 { | 52 { |
(...skipping 12 matching lines...) Expand all Loading... |
64 MutexLocker lock(threadSetMutex()); | 65 MutexLocker lock(threadSetMutex()); |
65 return workerThreads().size(); | 66 return workerThreads().size(); |
66 } | 67 } |
67 | 68 |
68 WorkerThread::WorkerThread(WorkerLoaderProxy& workerLoaderProxy, WorkerReporting
Proxy& workerReportingProxy, PassOwnPtr<WorkerThreadStartupData> startupData) | 69 WorkerThread::WorkerThread(WorkerLoaderProxy& workerLoaderProxy, WorkerReporting
Proxy& workerReportingProxy, PassOwnPtr<WorkerThreadStartupData> startupData) |
69 : m_threadID(0) | 70 : m_threadID(0) |
70 , m_workerLoaderProxy(workerLoaderProxy) | 71 , m_workerLoaderProxy(workerLoaderProxy) |
71 , m_workerReportingProxy(workerReportingProxy) | 72 , m_workerReportingProxy(workerReportingProxy) |
72 , m_startupData(startupData) | 73 , m_startupData(startupData) |
73 , m_notificationClient(0) | 74 , m_notificationClient(0) |
| 75 , m_shutdownEvent(adoptPtr(blink::Platform::current()->createWaitableEvent()
)) |
74 { | 76 { |
75 MutexLocker lock(threadSetMutex()); | 77 MutexLocker lock(threadSetMutex()); |
76 workerThreads().add(this); | 78 workerThreads().add(this); |
77 } | 79 } |
78 | 80 |
79 WorkerThread::~WorkerThread() | 81 WorkerThread::~WorkerThread() |
80 { | 82 { |
81 MutexLocker lock(threadSetMutex()); | 83 MutexLocker lock(threadSetMutex()); |
82 ASSERT(workerThreads().contains(this)); | 84 ASSERT(workerThreads().contains(this)); |
83 workerThreads().remove(this); | 85 workerThreads().remove(this); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 205 } |
204 | 206 |
205 virtual bool isCleanupTask() const { return true; } | 207 virtual bool isCleanupTask() const { return true; } |
206 }; | 208 }; |
207 | 209 |
208 void WorkerThread::stop() | 210 void WorkerThread::stop() |
209 { | 211 { |
210 // Mutex protection is necessary because stop() can be called before the con
text is fully created. | 212 // Mutex protection is necessary because stop() can be called before the con
text is fully created. |
211 MutexLocker lock(m_threadCreationMutex); | 213 MutexLocker lock(m_threadCreationMutex); |
212 | 214 |
| 215 // Signal the thread to notify that the thread's stopping. |
| 216 if (m_shutdownEvent) |
| 217 m_shutdownEvent->signal(); |
| 218 |
213 // Ensure that tasks are being handled by thread event loop. If script execu
tion weren't forbidden, a while(1) loop in JS could keep the thread alive foreve
r. | 219 // Ensure that tasks are being handled by thread event loop. If script execu
tion weren't forbidden, a while(1) loop in JS could keep the thread alive foreve
r. |
214 if (m_workerGlobalScope) { | 220 if (m_workerGlobalScope) { |
215 m_workerGlobalScope->script()->scheduleExecutionTermination(); | 221 m_workerGlobalScope->script()->scheduleExecutionTermination(); |
216 | 222 |
217 DatabaseManager::manager().interruptAllDatabasesForContext(m_workerGloba
lScope.get()); | 223 DatabaseManager::manager().interruptAllDatabasesForContext(m_workerGloba
lScope.get()); |
218 m_runLoop.postTaskAndTerminate(WorkerThreadShutdownStartTask::create()); | 224 m_runLoop.postTaskAndTerminate(WorkerThreadShutdownStartTask::create()); |
219 return; | 225 return; |
220 } | 226 } |
221 m_runLoop.terminate(); | 227 m_runLoop.terminate(); |
222 } | 228 } |
(...skipping 10 matching lines...) Expand all Loading... |
233 void WorkerThread::releaseFastMallocFreeMemoryInAllThreads() | 239 void WorkerThread::releaseFastMallocFreeMemoryInAllThreads() |
234 { | 240 { |
235 MutexLocker lock(threadSetMutex()); | 241 MutexLocker lock(threadSetMutex()); |
236 HashSet<WorkerThread*>& threads = workerThreads(); | 242 HashSet<WorkerThread*>& threads = workerThreads(); |
237 HashSet<WorkerThread*>::iterator end = threads.end(); | 243 HashSet<WorkerThread*>::iterator end = threads.end(); |
238 for (HashSet<WorkerThread*>::iterator it = threads.begin(); it != end; ++it) | 244 for (HashSet<WorkerThread*>::iterator it = threads.begin(); it != end; ++it) |
239 (*it)->runLoop().postTask(adoptPtr(new ReleaseFastMallocFreeMemoryTask))
; | 245 (*it)->runLoop().postTask(adoptPtr(new ReleaseFastMallocFreeMemoryTask))
; |
240 } | 246 } |
241 | 247 |
242 } // namespace WebCore | 248 } // namespace WebCore |
OLD | NEW |