Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 36 #include "platform/Logging.h" | 36 #include "platform/Logging.h" |
| 37 #include "platform/heap/glue/MessageLoopInterruptor.h" | 37 #include "platform/heap/glue/MessageLoopInterruptor.h" |
| 38 #include "platform/heap/glue/PendingGCRunner.h" | 38 #include "platform/heap/glue/PendingGCRunner.h" |
| 39 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 DatabaseThread::DatabaseThread() | 43 DatabaseThread::DatabaseThread() |
| 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) | |
| 47 , m_terminationRequested(false) | 46 , m_terminationRequested(false) |
| 48 { | 47 { |
| 49 } | 48 } |
| 50 | 49 |
| 51 DatabaseThread::~DatabaseThread() | 50 DatabaseThread::~DatabaseThread() |
| 52 { | 51 { |
| 53 ASSERT(m_openDatabaseSet.isEmpty()); | 52 ASSERT(m_openDatabaseSet.isEmpty()); |
| 54 // Oilpan: The database thread must have finished its cleanup tasks before | 53 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 } | 54 } |
| 62 | 55 |
| 63 void DatabaseThread::trace(Visitor* visitor) | 56 void DatabaseThread::trace(Visitor* visitor) |
| 64 { | 57 { |
| 65 #if ENABLE(OILPAN) | 58 #if ENABLE(OILPAN) |
| 66 visitor->trace(m_openDatabaseSet); | 59 visitor->trace(m_openDatabaseSet); |
| 67 visitor->trace(m_transactionCoordinator); | 60 visitor->trace(m_transactionCoordinator); |
| 68 #endif | 61 #endif |
| 69 } | 62 } |
| 70 | 63 |
| 71 void DatabaseThread::start() | 64 void DatabaseThread::start() |
| 72 { | 65 { |
| 73 if (m_thread) | 66 if (m_thread) |
| 74 return; | 67 return; |
| 75 m_thread = WebThreadSupportingGC::create("WebCore: Database"); | 68 m_thread = WebThreadSupportingGC::create("WebCore: Database"); |
| 76 m_thread->postTask(new Task(WTF::bind(&DatabaseThread::setupDatabaseThread, this))); | 69 m_thread->postTask(new Task(WTF::bind(&DatabaseThread::setupDatabaseThread, this))); |
| 77 } | 70 } |
| 78 | 71 |
| 79 void DatabaseThread::setupDatabaseThread() | 72 void DatabaseThread::setupDatabaseThread() |
| 80 { | 73 { |
| 81 m_thread->attachGC(); | 74 m_thread->attachGC(); |
| 82 } | 75 } |
| 83 | 76 |
| 84 void DatabaseThread::requestTermination(TaskSynchronizer *cleanupSync) | 77 void DatabaseThread::terminate() |
| 85 { | 78 { |
| 86 MutexLocker lock(m_terminationRequestedMutex); | 79 { |
| 87 ASSERT(!m_terminationRequested); | 80 MutexLocker lock(m_terminationRequestedMutex); |
| 88 m_terminationRequested = true; | 81 ASSERT(!m_terminationRequested); |
| 89 m_cleanupSync = cleanupSync; | 82 m_terminationRequested = true; |
| 90 WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); | 83 WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); |
| 91 m_thread->postTask(new Task(WTF::bind(&DatabaseThread::cleanupDatabaseThread , this))); | 84 m_thread->postTask(new Task(WTF::bind(&DatabaseThread::cleanupDatabaseTh read, this))); |
| 85 } | |
| 86 // The WebThread destructor blocks until the database thread processes the c leanup task. | |
| 87 m_thread.clear(); | |
|
Mads Ager (chromium)
2014/09/23 14:09:08
Hmm, how does this work. You post the cleanupDatab
| |
| 92 } | 88 } |
| 93 | 89 |
| 94 bool DatabaseThread::terminationRequested(TaskSynchronizer* taskSynchronizer) co nst | 90 bool DatabaseThread::terminationRequested(TaskSynchronizer* taskSynchronizer) co nst |
| 95 { | 91 { |
| 96 #if ENABLE(ASSERT) | 92 #if ENABLE(ASSERT) |
| 97 if (taskSynchronizer) | 93 if (taskSynchronizer) |
| 98 taskSynchronizer->setHasCheckedForTermination(); | 94 taskSynchronizer->setHasCheckedForTermination(); |
| 99 #endif | 95 #endif |
| 100 | 96 |
| 101 MutexLocker lock(m_terminationRequestedMutex); | 97 MutexLocker lock(m_terminationRequestedMutex); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 119 for (WillBeHeapHashSet<RefPtrWillBeMember<DatabaseBackend> >::iterator i t = openSetCopy.begin(); it != end; ++it) | 115 for (WillBeHeapHashSet<RefPtrWillBeMember<DatabaseBackend> >::iterator i t = openSetCopy.begin(); it != end; ++it) |
| 120 (*it)->close(); | 116 (*it)->close(); |
| 121 } | 117 } |
| 122 | 118 |
| 123 m_thread->postTask(new Task(WTF::bind(&DatabaseThread::cleanupDatabaseThread Completed, this))); | 119 m_thread->postTask(new Task(WTF::bind(&DatabaseThread::cleanupDatabaseThread Completed, this))); |
| 124 } | 120 } |
| 125 | 121 |
| 126 void DatabaseThread::cleanupDatabaseThreadCompleted() | 122 void DatabaseThread::cleanupDatabaseThreadCompleted() |
| 127 { | 123 { |
| 128 m_thread->detachGC(); | 124 m_thread->detachGC(); |
| 129 if (m_cleanupSync) // Someone wanted to know when we were done cleaning up. | |
| 130 m_cleanupSync->taskCompleted(); | |
| 131 } | 125 } |
| 132 | 126 |
| 133 void DatabaseThread::recordDatabaseOpen(DatabaseBackend* database) | 127 void DatabaseThread::recordDatabaseOpen(DatabaseBackend* database) |
| 134 { | 128 { |
| 135 ASSERT(isDatabaseThread()); | 129 ASSERT(isDatabaseThread()); |
| 136 ASSERT(database); | 130 ASSERT(database); |
| 137 ASSERT(!m_openDatabaseSet.contains(database)); | 131 ASSERT(!m_openDatabaseSet.contains(database)); |
| 138 m_openDatabaseSet.add(database); | 132 m_openDatabaseSet.add(database); |
| 139 } | 133 } |
| 140 | 134 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 156 | 150 |
| 157 void DatabaseThread::scheduleTask(PassOwnPtr<DatabaseTask> task) | 151 void DatabaseThread::scheduleTask(PassOwnPtr<DatabaseTask> task) |
| 158 { | 152 { |
| 159 ASSERT(m_thread); | 153 ASSERT(m_thread); |
| 160 ASSERT(!task->hasSynchronizer() || task->hasCheckedForTermination()); | 154 ASSERT(!task->hasSynchronizer() || task->hasCheckedForTermination()); |
| 161 // WebThread takes ownership of the task. | 155 // WebThread takes ownership of the task. |
| 162 m_thread->postTask(task.leakPtr()); | 156 m_thread->postTask(task.leakPtr()); |
| 163 } | 157 } |
| 164 | 158 |
| 165 } // namespace blink | 159 } // namespace blink |
| OLD | NEW |