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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // Stick a shutdown command at the end of the queue, so that we deal | 245 // Stick a shutdown command at the end of the queue, so that we deal |
246 // with all the cleanup tasks the databases post first. | 246 // with all the cleanup tasks the databases post first. |
247 workerContext->postTask(WorkerThreadShutdownFinishTask::create()); | 247 workerContext->postTask(WorkerThreadShutdownFinishTask::create()); |
248 } | 248 } |
249 | 249 |
250 virtual bool isCleanupTask() const { return true; } | 250 virtual bool isCleanupTask() const { return true; } |
251 }; | 251 }; |
252 | 252 |
253 void WorkerThread::stop() | 253 void WorkerThread::stop() |
254 { | 254 { |
255 ThreadState::PauseScope pauseScope(ThreadState::HeapPointersOnStack); | 255 ThreadState::SafePointScope safePointScope(ThreadState::HeapPointersOnStack)
; |
256 | 256 |
257 // Mutex protection is necessary because stop() can be called before the con
text is fully created. | 257 // Mutex protection is necessary because stop() can be called before the con
text is fully created. |
258 MutexLocker lock(m_threadCreationMutex); | 258 MutexLocker lock(m_threadCreationMutex); |
259 | 259 |
260 // 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. | 260 // 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. |
261 if (m_workerContext && workerContext()) { | 261 if (m_workerContext && workerContext()) { |
262 workerContext()->script()->scheduleExecutionTermination(); | 262 workerContext()->script()->scheduleExecutionTermination(); |
263 | 263 |
264 DatabaseManager::manager().interruptAllDatabasesForContext(workerContext
()); | 264 DatabaseManager::manager().interruptAllDatabasesForContext(workerContext
()); |
265 m_runLoop.postTaskAndTerminate(WorkerThreadShutdownStartTask::create()); | 265 m_runLoop.postTaskAndTerminate(WorkerThreadShutdownStartTask::create()); |
266 return; | 266 return; |
267 } | 267 } |
268 m_runLoop.terminate(); | 268 m_runLoop.terminate(); |
269 } | 269 } |
270 | 270 |
271 class ReleaseFastMallocFreeMemoryTask : public ScriptExecutionContext::Task { | 271 class ReleaseFastMallocFreeMemoryTask : public ScriptExecutionContext::Task { |
272 virtual void performTask(ScriptExecutionContext*) OVERRIDE { WTF::releaseFas
tMallocFreeMemory(); } | 272 virtual void performTask(ScriptExecutionContext*) OVERRIDE { WTF::releaseFas
tMallocFreeMemory(); } |
273 }; | 273 }; |
274 | 274 |
275 void WorkerThread::releaseFastMallocFreeMemoryInAllThreads() | 275 void WorkerThread::releaseFastMallocFreeMemoryInAllThreads() |
276 { | 276 { |
277 MutexLocker lock(threadSetMutex()); | 277 MutexLocker lock(threadSetMutex()); |
278 HashSet<WorkerThread*>& threads = workerThreads(); | 278 HashSet<WorkerThread*>& threads = workerThreads(); |
279 HashSet<WorkerThread*>::iterator end = threads.end(); | 279 HashSet<WorkerThread*>::iterator end = threads.end(); |
280 for (HashSet<WorkerThread*>::iterator it = threads.begin(); it != end; ++it) | 280 for (HashSet<WorkerThread*>::iterator it = threads.begin(); it != end; ++it) |
281 (*it)->runLoop().postTask(adoptPtr(new ReleaseFastMallocFreeMemoryTask))
; | 281 (*it)->runLoop().postTask(adoptPtr(new ReleaseFastMallocFreeMemoryTask))
; |
282 } | 282 } |
283 | 283 |
284 } // namespace WebCore | 284 } // namespace WebCore |
OLD | NEW |