| 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 16 matching lines...) Expand all Loading... |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "modules/webdatabase/DatabaseThread.h" | 29 #include "modules/webdatabase/DatabaseThread.h" |
| 30 | 30 |
| 31 #include "modules/webdatabase/Database.h" | 31 #include "modules/webdatabase/Database.h" |
| 32 #include "modules/webdatabase/DatabaseTask.h" | 32 #include "modules/webdatabase/DatabaseTask.h" |
| 33 #include "modules/webdatabase/SQLTransactionClient.h" | 33 #include "modules/webdatabase/SQLTransactionClient.h" |
| 34 #include "modules/webdatabase/SQLTransactionCoordinator.h" | 34 #include "modules/webdatabase/SQLTransactionCoordinator.h" |
| 35 #include "modules/webdatabase/StorageLog.h" | 35 #include "modules/webdatabase/StorageLog.h" |
| 36 #include "platform/CrossThreadFunctional.h" | 36 #include "platform/CrossThreadFunctional.h" |
| 37 #include "platform/WaitableEvent.h" |
| 37 #include "platform/WebThreadSupportingGC.h" | 38 #include "platform/WebThreadSupportingGC.h" |
| 38 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
| 39 #include "wtf/PtrUtil.h" | 40 #include "wtf/PtrUtil.h" |
| 40 #include <memory> | 41 #include <memory> |
| 41 | 42 |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 44 DatabaseThread::DatabaseThread() | 45 DatabaseThread::DatabaseThread() |
| 45 : m_transactionClient(wrapUnique(new SQLTransactionClient())) | 46 : m_transactionClient(wrapUnique(new SQLTransactionClient())) |
| 46 , m_cleanupSync(nullptr) | 47 , m_cleanupSync(nullptr) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 70 | 71 |
| 71 void DatabaseThread::setupDatabaseThread() | 72 void DatabaseThread::setupDatabaseThread() |
| 72 { | 73 { |
| 73 m_thread->initialize(); | 74 m_thread->initialize(); |
| 74 m_transactionCoordinator = new SQLTransactionCoordinator(); | 75 m_transactionCoordinator = new SQLTransactionCoordinator(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void DatabaseThread::terminate() | 78 void DatabaseThread::terminate() |
| 78 { | 79 { |
| 79 ASSERT(isMainThread()); | 80 ASSERT(isMainThread()); |
| 80 TaskSynchronizer sync; | 81 WaitableEvent sync; |
| 81 { | 82 { |
| 82 MutexLocker lock(m_terminationRequestedMutex); | 83 MutexLocker lock(m_terminationRequestedMutex); |
| 83 ASSERT(!m_terminationRequested); | 84 ASSERT(!m_terminationRequested); |
| 84 m_terminationRequested = true; | 85 m_terminationRequested = true; |
| 85 m_cleanupSync = &sync; | 86 m_cleanupSync = &sync; |
| 86 STORAGE_DVLOG(1) << "DatabaseThread " << this << " was asked to terminat
e"; | 87 STORAGE_DVLOG(1) << "DatabaseThread " << this << " was asked to terminat
e"; |
| 87 m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseThread::cle
anupDatabaseThread, wrapCrossThreadPersistent(this))); | 88 m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseThread::cle
anupDatabaseThread, wrapCrossThreadPersistent(this))); |
| 88 } | 89 } |
| 89 sync.waitForTaskCompletion(); | 90 sync.wait(); |
| 90 // The WebThread destructor blocks until all the tasks of the database | 91 // The WebThread destructor blocks until all the tasks of the database |
| 91 // thread are processed. However, it shouldn't block at all because | 92 // thread are processed. However, it shouldn't block at all because |
| 92 // the database thread has already finished processing the cleanup task. | 93 // the database thread has already finished processing the cleanup task. |
| 93 m_thread.reset(); | 94 m_thread.reset(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void DatabaseThread::cleanupDatabaseThread() | 97 void DatabaseThread::cleanupDatabaseThread() |
| 97 { | 98 { |
| 98 DCHECK(isDatabaseThread()); | 99 DCHECK(isDatabaseThread()); |
| 99 | 100 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 114 } | 115 } |
| 115 m_openDatabaseSet.clear(); | 116 m_openDatabaseSet.clear(); |
| 116 | 117 |
| 117 m_thread->postTask(BLINK_FROM_HERE, WTF::bind(&DatabaseThread::cleanupDataba
seThreadCompleted, wrapCrossThreadPersistent(this))); | 118 m_thread->postTask(BLINK_FROM_HERE, WTF::bind(&DatabaseThread::cleanupDataba
seThreadCompleted, wrapCrossThreadPersistent(this))); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void DatabaseThread::cleanupDatabaseThreadCompleted() | 121 void DatabaseThread::cleanupDatabaseThreadCompleted() |
| 121 { | 122 { |
| 122 m_thread->shutdown(); | 123 m_thread->shutdown(); |
| 123 if (m_cleanupSync) // Someone wanted to know when we were done cleaning up. | 124 if (m_cleanupSync) // Someone wanted to know when we were done cleaning up. |
| 124 m_cleanupSync->taskCompleted(); | 125 m_cleanupSync->signal(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 void DatabaseThread::recordDatabaseOpen(Database* database) | 128 void DatabaseThread::recordDatabaseOpen(Database* database) |
| 128 { | 129 { |
| 129 ASSERT(isDatabaseThread()); | 130 ASSERT(isDatabaseThread()); |
| 130 ASSERT(database); | 131 ASSERT(database); |
| 131 ASSERT(!m_openDatabaseSet.contains(database)); | 132 ASSERT(!m_openDatabaseSet.contains(database)); |
| 132 MutexLocker lock(m_terminationRequestedMutex); | 133 MutexLocker lock(m_terminationRequestedMutex); |
| 133 if (!m_terminationRequested) | 134 if (!m_terminationRequested) |
| 134 m_openDatabaseSet.add(database); | 135 m_openDatabaseSet.add(database); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 { | 170 { |
| 170 MutexLocker lock(m_terminationRequestedMutex); | 171 MutexLocker lock(m_terminationRequestedMutex); |
| 171 ASSERT(!m_terminationRequested); | 172 ASSERT(!m_terminationRequested); |
| 172 } | 173 } |
| 173 #endif | 174 #endif |
| 174 // WebThread takes ownership of the task. | 175 // WebThread takes ownership of the task. |
| 175 m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseTask::run, std:
:move(task))); | 176 m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseTask::run, std:
:move(task))); |
| 176 } | 177 } |
| 177 | 178 |
| 178 } // namespace blink | 179 } // namespace blink |
| OLD | NEW |