| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2013 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 : m_transactionClient(adoptPtr(new SQLTransactionClient())) | 44 : m_transactionClient(adoptPtr(new SQLTransactionClient())) |
| 45 , m_transactionCoordinator(adoptPtrWillBeNoop(new SQLTransactionCoordinator(
))) | 45 , m_transactionCoordinator(adoptPtrWillBeNoop(new SQLTransactionCoordinator(
))) |
| 46 , m_cleanupSync(0) | 46 , m_cleanupSync(0) |
| 47 , m_terminationRequested(false) | 47 , m_terminationRequested(false) |
| 48 { | 48 { |
| 49 } | 49 } |
| 50 | 50 |
| 51 DatabaseThread::~DatabaseThread() | 51 DatabaseThread::~DatabaseThread() |
| 52 { | 52 { |
| 53 ASSERT(m_openDatabaseSet.isEmpty()); | 53 ASSERT(m_openDatabaseSet.isEmpty()); |
| 54 // Oilpan: The database thread must have finished its cleanup tasks before | 54 ASSERT(!m_thread); |
| 55 // the following clear(). Otherwise, WebThread destructor blocks the caller | |
| 56 // thread, and causes a deadlock with ThreadState cleanup. | |
| 57 // DatabaseContext::stop() asks the database thread to close all of | |
| 58 // databases, and wait until GC heap cleanup of the database thread. So we | |
| 59 // can safely destruct WebThread here. | |
| 60 m_thread.clear(); | |
| 61 } | 55 } |
| 62 | 56 |
| 63 void DatabaseThread::trace(Visitor* visitor) | 57 void DatabaseThread::trace(Visitor* visitor) |
| 64 { | 58 { |
| 65 #if ENABLE(OILPAN) | 59 #if ENABLE(OILPAN) |
| 66 visitor->trace(m_openDatabaseSet); | 60 visitor->trace(m_openDatabaseSet); |
| 67 visitor->trace(m_transactionCoordinator); | 61 visitor->trace(m_transactionCoordinator); |
| 68 #endif | 62 #endif |
| 69 } | 63 } |
| 70 | 64 |
| 71 void DatabaseThread::start() | 65 void DatabaseThread::start() |
| 72 { | 66 { |
| 73 if (m_thread) | 67 if (m_thread) |
| 74 return; | 68 return; |
| 75 m_thread = WebThreadSupportingGC::create("WebCore: Database"); | 69 m_thread = WebThreadSupportingGC::create("WebCore: Database"); |
| 76 m_thread->postTask(new Task(WTF::bind(&DatabaseThread::setupDatabaseThread,
this))); | 70 m_thread->postTask(new Task(WTF::bind(&DatabaseThread::setupDatabaseThread,
this))); |
| 77 } | 71 } |
| 78 | 72 |
| 79 void DatabaseThread::setupDatabaseThread() | 73 void DatabaseThread::setupDatabaseThread() |
| 80 { | 74 { |
| 81 m_thread->attachGC(); | 75 m_thread->attachGC(); |
| 82 } | 76 } |
| 83 | 77 |
| 84 void DatabaseThread::requestTermination(TaskSynchronizer *cleanupSync) | 78 void DatabaseThread::terminate() |
| 85 { | 79 { |
| 86 MutexLocker lock(m_terminationRequestedMutex); | 80 TaskSynchronizer sync; |
| 87 ASSERT(!m_terminationRequested); | 81 { |
| 88 m_terminationRequested = true; | 82 MutexLocker lock(m_terminationRequestedMutex); |
| 89 m_cleanupSync = cleanupSync; | 83 ASSERT(!m_terminationRequested); |
| 90 WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); | 84 m_terminationRequested = true; |
| 91 m_thread->postTask(new Task(WTF::bind(&DatabaseThread::cleanupDatabaseThread
, this))); | 85 m_cleanupSync = &sync; |
| 86 WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); |
| 87 m_thread->postTask(new Task(WTF::bind(&DatabaseThread::cleanupDatabaseTh
read, this))); |
| 88 } |
| 89 sync.waitForTaskCompletion(); |
| 90 // The WebThread destructor blocks until all the tasks of the database |
| 91 // thread are processed. However, it shouldn't block at all because |
| 92 // the database thread has already finished processing the cleanup task. |
| 93 m_thread.clear(); |
| 92 } | 94 } |
| 93 | 95 |
| 94 bool DatabaseThread::terminationRequested() const | 96 bool DatabaseThread::terminationRequested() const |
| 95 { | 97 { |
| 96 MutexLocker lock(m_terminationRequestedMutex); | 98 MutexLocker lock(m_terminationRequestedMutex); |
| 97 return m_terminationRequested; | 99 return m_terminationRequested; |
| 98 } | 100 } |
| 99 | 101 |
| 100 void DatabaseThread::cleanupDatabaseThread() | 102 void DatabaseThread::cleanupDatabaseThread() |
| 101 { | 103 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 153 |
| 152 void DatabaseThread::scheduleTask(PassOwnPtr<DatabaseTask> task) | 154 void DatabaseThread::scheduleTask(PassOwnPtr<DatabaseTask> task) |
| 153 { | 155 { |
| 154 ASSERT(m_thread); | 156 ASSERT(m_thread); |
| 155 ASSERT(!terminationRequested()); | 157 ASSERT(!terminationRequested()); |
| 156 // WebThread takes ownership of the task. | 158 // WebThread takes ownership of the task. |
| 157 m_thread->postTask(task.leakPtr()); | 159 m_thread->postTask(task.leakPtr()); |
| 158 } | 160 } |
| 159 | 161 |
| 160 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |