| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 return true; | 70 return true; |
| 71 | 71 |
| 72 m_threadID = createThread(DatabaseThread::databaseThreadStart, this, "WebCor
e: Database"); | 72 m_threadID = createThread(DatabaseThread::databaseThreadStart, this, "WebCor
e: Database"); |
| 73 | 73 |
| 74 return m_threadID; | 74 return m_threadID; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void DatabaseThread::requestTermination(DatabaseTaskSynchronizer *cleanupSync) | 77 void DatabaseThread::requestTermination(DatabaseTaskSynchronizer *cleanupSync) |
| 78 { | 78 { |
| 79 m_cleanupSync = cleanupSync; | 79 m_cleanupSync = cleanupSync; |
| 80 LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); | 80 LOG_INFO(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); |
| 81 m_queue.kill(); | 81 m_queue.kill(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool DatabaseThread::terminationRequested(DatabaseTaskSynchronizer* taskSynchron
izer) const | 84 bool DatabaseThread::terminationRequested(DatabaseTaskSynchronizer* taskSynchron
izer) const |
| 85 { | 85 { |
| 86 #ifndef NDEBUG | 86 #ifndef NDEBUG |
| 87 if (taskSynchronizer) | 87 if (taskSynchronizer) |
| 88 taskSynchronizer->setHasCheckedForTermination(); | 88 taskSynchronizer->setHasCheckedForTermination(); |
| 89 #else | 89 #else |
| 90 UNUSED_PARAM(taskSynchronizer); | 90 UNUSED_PARAM(taskSynchronizer); |
| 91 #endif | 91 #endif |
| 92 | 92 |
| 93 return m_queue.killed(); | 93 return m_queue.killed(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void DatabaseThread::databaseThreadStart(void* vDatabaseThread) | 96 void DatabaseThread::databaseThreadStart(void* vDatabaseThread) |
| 97 { | 97 { |
| 98 DatabaseThread* dbThread = static_cast<DatabaseThread*>(vDatabaseThread); | 98 DatabaseThread* dbThread = static_cast<DatabaseThread*>(vDatabaseThread); |
| 99 dbThread->databaseThread(); | 99 dbThread->databaseThread(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void DatabaseThread::databaseThread() | 102 void DatabaseThread::databaseThread() |
| 103 { | 103 { |
| 104 { | 104 { |
| 105 // Wait for DatabaseThread::start() to complete. | 105 // Wait for DatabaseThread::start() to complete. |
| 106 MutexLocker lock(m_threadCreationMutex); | 106 MutexLocker lock(m_threadCreationMutex); |
| 107 LOG(StorageAPI, "Started DatabaseThread %p", this); | 107 LOG_INFO(StorageAPI, "Started DatabaseThread %p", this); |
| 108 } | 108 } |
| 109 | 109 |
| 110 AutodrainedPool pool; | 110 AutodrainedPool pool; |
| 111 while (OwnPtr<DatabaseTask> task = m_queue.waitForMessage()) { | 111 while (OwnPtr<DatabaseTask> task = m_queue.waitForMessage()) { |
| 112 task->performTask(); | 112 task->performTask(); |
| 113 pool.cycle(); | 113 pool.cycle(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 // Clean up the list of all pending transactions on this database thread | 116 // Clean up the list of all pending transactions on this database thread |
| 117 m_transactionCoordinator->shutdown(); | 117 m_transactionCoordinator->shutdown(); |
| 118 | 118 |
| 119 LOG(StorageAPI, "About to detach thread %i and clear the ref to DatabaseThre
ad %p, which currently has %i ref(s)", m_threadID, this, refCount()); | 119 LOG_INFO(StorageAPI, "About to detach thread %i and clear the ref to Databas
eThread %p, which currently has %i ref(s)", m_threadID, this, refCount()); |
| 120 | 120 |
| 121 // Close the databases that we ran transactions on. This ensures that if any
transactions are still open, they are rolled back and we don't leave the databa
se in an | 121 // Close the databases that we ran transactions on. This ensures that if any
transactions are still open, they are rolled back and we don't leave the databa
se in an |
| 122 // inconsistent or locked state. | 122 // inconsistent or locked state. |
| 123 if (m_openDatabaseSet.size() > 0) { | 123 if (m_openDatabaseSet.size() > 0) { |
| 124 // As the call to close will modify the original set, we must take a cop
y to iterate over. | 124 // As the call to close will modify the original set, we must take a cop
y to iterate over. |
| 125 DatabaseSet openSetCopy; | 125 DatabaseSet openSetCopy; |
| 126 openSetCopy.swap(m_openDatabaseSet); | 126 openSetCopy.swap(m_openDatabaseSet); |
| 127 DatabaseSet::iterator end = openSetCopy.end(); | 127 DatabaseSet::iterator end = openSetCopy.end(); |
| 128 for (DatabaseSet::iterator it = openSetCopy.begin(); it != end; ++it) | 128 for (DatabaseSet::iterator it = openSetCopy.begin(); it != end; ++it) |
| 129 (*it).get()->close(); | 129 (*it).get()->close(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 179 |
| 180 void DatabaseThread::unscheduleDatabaseTasks(DatabaseBackend* database) | 180 void DatabaseThread::unscheduleDatabaseTasks(DatabaseBackend* database) |
| 181 { | 181 { |
| 182 // Note that the thread loop is running, so some tasks for the database | 182 // Note that the thread loop is running, so some tasks for the database |
| 183 // may still be executed. This is unavoidable. | 183 // may still be executed. This is unavoidable. |
| 184 SameDatabasePredicate predicate(database); | 184 SameDatabasePredicate predicate(database); |
| 185 m_queue.removeIf(predicate); | 185 m_queue.removeIf(predicate); |
| 186 } | 186 } |
| 187 } // namespace WebCore | 187 } // namespace WebCore |
| 188 #endif | 188 #endif |
| OLD | NEW |