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 30 matching lines...) Expand all Loading... |
41 DatabaseThread::DatabaseThread() | 41 DatabaseThread::DatabaseThread() |
42 : m_transactionClient(adoptPtr(new SQLTransactionClient())) | 42 : m_transactionClient(adoptPtr(new SQLTransactionClient())) |
43 , m_transactionCoordinator(adoptPtr(new SQLTransactionCoordinator())) | 43 , m_transactionCoordinator(adoptPtr(new SQLTransactionCoordinator())) |
44 , m_cleanupSync(0) | 44 , m_cleanupSync(0) |
45 , m_terminationRequested(false) | 45 , m_terminationRequested(false) |
46 { | 46 { |
47 } | 47 } |
48 | 48 |
49 DatabaseThread::~DatabaseThread() | 49 DatabaseThread::~DatabaseThread() |
50 { | 50 { |
51 ASSERT(m_thread); | |
52 ASSERT(!isDatabaseThread()); | |
53 bool terminationRequested; | 51 bool terminationRequested; |
54 { | 52 { |
55 MutexLocker lock(m_terminationRequestedMutex); | 53 MutexLocker lock(m_terminationRequestedMutex); |
56 terminationRequested = m_terminationRequested; | 54 terminationRequested = m_terminationRequested; |
57 } | 55 } |
58 if (!terminationRequested) | 56 if (!terminationRequested) |
59 requestTermination(0); | 57 requestTermination(0); |
60 m_thread.clear(); | 58 m_thread.clear(); |
61 } | 59 } |
62 | 60 |
(...skipping 28 matching lines...) Expand all Loading... |
91 void DatabaseThread::cleanupDatabaseThread() | 89 void DatabaseThread::cleanupDatabaseThread() |
92 { | 90 { |
93 WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this); | 91 WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this); |
94 | 92 |
95 // Clean up the list of all pending transactions on this database thread | 93 // Clean up the list of all pending transactions on this database thread |
96 m_transactionCoordinator->shutdown(); | 94 m_transactionCoordinator->shutdown(); |
97 | 95 |
98 // 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 | 96 // 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 |
99 // inconsistent or locked state. | 97 // inconsistent or locked state. |
100 if (m_openDatabaseSet.size() > 0) { | 98 if (m_openDatabaseSet.size() > 0) { |
101 DatabaseSet::iterator end = m_openDatabaseSet.end(); | 99 // As the call to close will modify the original set, we must take a cop
y to iterate over. |
102 for (DatabaseSet::iterator it = m_openDatabaseSet.begin(); it != end; ++
it) | 100 DatabaseSet openSetCopy; |
| 101 openSetCopy.swap(m_openDatabaseSet); |
| 102 DatabaseSet::iterator end = openSetCopy.end(); |
| 103 for (DatabaseSet::iterator it = openSetCopy.begin(); it != end; ++it) |
103 (*it).get()->close(); | 104 (*it).get()->close(); |
104 } | 105 } |
105 | 106 |
106 if (m_cleanupSync) // Someone wanted to know when we were done cleaning up. | 107 if (m_cleanupSync) // Someone wanted to know when we were done cleaning up. |
107 m_thread->postTask(new Task(WTF::bind(&DatabaseTaskSynchronizer::taskCom
pleted, m_cleanupSync))); | 108 m_thread->postTask(new Task(WTF::bind(&DatabaseTaskSynchronizer::taskCom
pleted, m_cleanupSync))); |
108 } | 109 } |
109 | 110 |
110 void DatabaseThread::recordDatabaseOpen(DatabaseBackend* database) | 111 void DatabaseThread::recordDatabaseOpen(DatabaseBackend* database) |
111 { | 112 { |
112 ASSERT(isDatabaseThread()); | 113 ASSERT(isDatabaseThread()); |
113 ASSERT(database); | 114 ASSERT(database); |
114 ASSERT(!m_openDatabaseSet.contains(database)); | 115 ASSERT(!m_openDatabaseSet.contains(database)); |
115 m_openDatabaseSet.add(database); | 116 m_openDatabaseSet.add(database); |
116 } | 117 } |
117 | 118 |
118 void DatabaseThread::recordDatabaseClosed(DatabaseBackend* database) | 119 void DatabaseThread::recordDatabaseClosed(DatabaseBackend* database) |
119 { | 120 { |
120 #ifndef ASSERT_DISABLED | 121 #ifndef ASSERT_DISABLED |
121 MutexLocker lock(m_terminationRequestedMutex); | 122 MutexLocker lock(m_terminationRequestedMutex); |
122 #endif | 123 #endif |
123 ASSERT(isDatabaseThread()); | 124 ASSERT(isDatabaseThread()); |
124 ASSERT_UNUSED(database, database); | 125 ASSERT(database); |
125 ASSERT(m_terminationRequested || m_openDatabaseSet.contains(database)); | 126 ASSERT(m_terminationRequested || m_openDatabaseSet.contains(database)); |
126 // We'll clear m_openDatabaseSet in the destructor. | 127 m_openDatabaseSet.remove(database); |
| 128 } |
| 129 |
| 130 bool DatabaseThread::isDatabaseOpen(DatabaseBackend* database) |
| 131 { |
| 132 ASSERT(isDatabaseThread()); |
| 133 ASSERT(database); |
| 134 MutexLocker lock(m_terminationRequestedMutex); |
| 135 return !m_terminationRequested && m_openDatabaseSet.contains(database); |
127 } | 136 } |
128 | 137 |
129 void DatabaseThread::scheduleTask(PassOwnPtr<DatabaseTask> task) | 138 void DatabaseThread::scheduleTask(PassOwnPtr<DatabaseTask> task) |
130 { | 139 { |
131 ASSERT(m_thread); | 140 ASSERT(m_thread); |
132 ASSERT(!task->hasSynchronizer() || task->hasCheckedForTermination()); | 141 ASSERT(!task->hasSynchronizer() || task->hasCheckedForTermination()); |
133 // WebThread takes ownership of the task. | 142 // WebThread takes ownership of the task. |
134 m_thread->postTask(task.leakPtr()); | 143 m_thread->postTask(task.leakPtr()); |
135 } | 144 } |
136 | 145 |
137 } // namespace WebCore | 146 } // namespace WebCore |
OLD | NEW |