Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/Source/modules/webdatabase/DatabaseThread.cpp

Issue 2037233002: Revert of Enable per thread heap for database thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 #include "modules/webdatabase/SQLTransactionCoordinator.h" 34 #include "modules/webdatabase/SQLTransactionCoordinator.h"
35 #include "platform/Logging.h" 35 #include "platform/Logging.h"
36 #include "platform/ThreadSafeFunctional.h" 36 #include "platform/ThreadSafeFunctional.h"
37 #include "platform/WebThreadSupportingGC.h" 37 #include "platform/WebThreadSupportingGC.h"
38 #include "public/platform/Platform.h" 38 #include "public/platform/Platform.h"
39 39
40 namespace blink { 40 namespace blink {
41 41
42 DatabaseThread::DatabaseThread() 42 DatabaseThread::DatabaseThread()
43 : m_transactionClient(adoptPtr(new SQLTransactionClient())) 43 : m_transactionClient(adoptPtr(new SQLTransactionClient()))
44 , m_transactionCoordinator(new SQLTransactionCoordinator())
44 , m_cleanupSync(nullptr) 45 , m_cleanupSync(nullptr)
45 , m_terminationRequested(false) 46 , m_terminationRequested(false)
46 { 47 {
47 DCHECK(isMainThread());
48 } 48 }
49 49
50 DatabaseThread::~DatabaseThread() 50 DatabaseThread::~DatabaseThread()
51 { 51 {
52 ASSERT(m_openDatabaseSet.isEmpty()); 52 ASSERT(m_openDatabaseSet.isEmpty());
53 ASSERT(!m_thread); 53 ASSERT(!m_thread);
54 } 54 }
55 55
56 DEFINE_TRACE(DatabaseThread) 56 DEFINE_TRACE(DatabaseThread)
57 { 57 {
58 visitor->trace(m_openDatabaseSet);
59 visitor->trace(m_transactionCoordinator);
58 } 60 }
59 61
60 void DatabaseThread::start() 62 void DatabaseThread::start()
61 { 63 {
62 ASSERT(isMainThread()); 64 ASSERT(isMainThread());
63 if (m_thread) 65 if (m_thread)
64 return; 66 return;
65 m_thread = WebThreadSupportingGC::create("WebCore: Database", true); 67 m_thread = WebThreadSupportingGC::create("WebCore: Database");
66 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::setupDat abaseThread, wrapCrossThreadPersistent(this))); 68 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::setupDat abaseThread, wrapCrossThreadPersistent(this)));
67 } 69 }
68 70
69 void DatabaseThread::setupDatabaseThread() 71 void DatabaseThread::setupDatabaseThread()
70 { 72 {
71 m_thread->initialize(); 73 m_thread->initialize();
72 m_transactionCoordinator = new SQLTransactionCoordinator();
73 } 74 }
74 75
75 void DatabaseThread::terminate() 76 void DatabaseThread::terminate()
76 { 77 {
77 ASSERT(isMainThread()); 78 ASSERT(isMainThread());
78 TaskSynchronizer sync; 79 TaskSynchronizer sync;
79 { 80 {
80 MutexLocker lock(m_terminationRequestedMutex); 81 MutexLocker lock(m_terminationRequestedMutex);
81 ASSERT(!m_terminationRequested); 82 ASSERT(!m_terminationRequested);
82 m_terminationRequested = true; 83 m_terminationRequested = true;
83 m_cleanupSync = &sync; 84 m_cleanupSync = &sync;
84 WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); 85 WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this);
85 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::clea nupDatabaseThread, wrapCrossThreadPersistent(this))); 86 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::clea nupDatabaseThread, wrapCrossThreadPersistent(this)));
86 } 87 }
87 sync.waitForTaskCompletion(); 88 sync.waitForTaskCompletion();
88 // The WebThread destructor blocks until all the tasks of the database 89 // The WebThread destructor blocks until all the tasks of the database
89 // thread are processed. However, it shouldn't block at all because 90 // thread are processed. However, it shouldn't block at all because
90 // the database thread has already finished processing the cleanup task. 91 // the database thread has already finished processing the cleanup task.
91 m_thread.reset(); 92 m_thread.reset();
92 } 93 }
93 94
94 void DatabaseThread::cleanupDatabaseThread() 95 void DatabaseThread::cleanupDatabaseThread()
95 { 96 {
96 DCHECK(isDatabaseThread());
97
98 WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this); 97 WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this);
99 98
100 // Clean up the list of all pending transactions on this database thread 99 // Clean up the list of all pending transactions on this database thread
101 m_transactionCoordinator->shutdown(); 100 m_transactionCoordinator->shutdown();
102 101
103 // 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 102 // 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
104 // inconsistent or locked state. 103 // inconsistent or locked state.
105 if (m_openDatabaseSet.size() > 0) { 104 if (m_openDatabaseSet.size() > 0) {
106 // As the call to close will modify the original set, we must take a cop y to iterate over. 105 // As the call to close will modify the original set, we must take a cop y to iterate over.
107 HashSet<CrossThreadPersistent<Database>> openSetCopy; 106 HeapHashSet<Member<Database>> openSetCopy;
108 openSetCopy.swap(m_openDatabaseSet); 107 openSetCopy.swap(m_openDatabaseSet);
109 HashSet<CrossThreadPersistent<Database>>::iterator end = openSetCopy.end (); 108 HeapHashSet<Member<Database>>::iterator end = openSetCopy.end();
110 for (HashSet<CrossThreadPersistent<Database>>::iterator it = openSetCopy .begin(); it != end; ++it) 109 for (HeapHashSet<Member<Database>>::iterator it = openSetCopy.begin(); i t != end; ++it)
111 (*it)->close(); 110 (*it)->close();
112 } 111 }
113 m_openDatabaseSet.clear(); 112 m_openDatabaseSet.clear();
114 113
115 m_thread->postTask(BLINK_FROM_HERE, WTF::bind(&DatabaseThread::cleanupDataba seThreadCompleted, this)); 114 m_thread->postTask(BLINK_FROM_HERE, WTF::bind(&DatabaseThread::cleanupDataba seThreadCompleted, this));
116 } 115 }
117 116
118 void DatabaseThread::cleanupDatabaseThreadCompleted() 117 void DatabaseThread::cleanupDatabaseThreadCompleted()
119 { 118 {
120 m_thread->shutdown(); 119 m_thread->shutdown();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 { 166 {
168 MutexLocker lock(m_terminationRequestedMutex); 167 MutexLocker lock(m_terminationRequestedMutex);
169 ASSERT(!m_terminationRequested); 168 ASSERT(!m_terminationRequested);
170 } 169 }
171 #endif 170 #endif
172 // WebThread takes ownership of the task. 171 // WebThread takes ownership of the task.
173 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseTask::run, std:: move(task))); 172 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseTask::run, std:: move(task)));
174 } 173 }
175 174
176 } // namespace blink 175 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698