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