Changeset 52367 in webkit


Ignore:
Timestamp:
Dec 18, 2009 5:27:14 PM (14 years ago)
Author:
dumi@chromium.org
Message:

Move some code related to database closing from the destructor to
the close() method. This would allow us to do things such as post
tasks to other threads when a database closes, which cannot be
done now, because we cannot increment the ref count to a database
object when we're in its destructor.

Reviewed by Dmitry Titov.

https://bugs.webkit.org/show_bug.cgi?id=32626

  • storage/Database.cpp:

(WebCore::Database::~Database):
(WebCore::Database::close):

Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r52354 r52367  
     12009-12-16  Dumitru Daniliuc  <dumi@chromium.org>
     2
     3        Reviewed by Dmitry Titov.
     4
     5        Move some code related to database closing from the destructor to
     6        the close() method. This would allow us to do things such as post
     7        tasks to other threads when a database closes, which cannot be
     8        done now, because we cannot increment the ref count to a database
     9        object when we're in its destructor.
     10
     11        https://bugs.webkit.org/show_bug.cgi?id=32626
     12
     13        * storage/Database.cpp:
     14        (WebCore::Database::~Database):
     15        (WebCore::Database::close):
     16
    1172009-12-18  Jon Honeycutt  <jhoneycutt@apple.com>
    218
  • trunk/WebCore/storage/Database.cpp

    r50666 r52367  
    199199Database::~Database()
    200200{
    201     if (m_document->databaseThread())
    202         m_document->databaseThread()->unscheduleDatabaseTasks(this);
    203 
    204     DatabaseTracker::tracker().removeOpenDatabase(this);
    205     m_document->removeOpenDatabase(this);
    206 
    207201    // Deref m_document on the main thread.
    208202    callOnMainThread(derefDocument, m_document.release().releaseRef());
     
    334328}
    335329
     330static void documentRemoveOpenDatabase(void* context)
     331{
     332    ASSERT(isMainThread());
     333    Database* database = static_cast<Database*>(context);
     334    database->document()->removeOpenDatabase(database);
     335    database->deref();
     336}
     337
    336338void Database::close()
    337339{
    338     if (m_opened) {
    339         ASSERT(m_document->databaseThread());
    340         ASSERT(currentThread() == document()->databaseThread()->getThreadID());
    341         m_sqliteDatabase.close();
    342         m_document->databaseThread()->recordDatabaseClosed(this);
    343         m_opened = false;
    344 
    345         {
    346             MutexLocker locker(guidMutex());
    347 
    348             HashSet<Database*>* hashSet = guidToDatabaseMap().get(m_guid);
    349             ASSERT(hashSet);
    350             ASSERT(hashSet->contains(this));
    351             hashSet->remove(this);
    352             if (hashSet->isEmpty()) {
    353                 guidToDatabaseMap().remove(m_guid);
    354                 delete hashSet;
    355                 guidToVersionMap().remove(m_guid);
    356             }
     340    if (!m_opened)
     341        return;
     342
     343    ASSERT(m_document->databaseThread());
     344    ASSERT(currentThread() == document()->databaseThread()->getThreadID());
     345    m_sqliteDatabase.close();
     346    m_document->databaseThread()->recordDatabaseClosed(this);
     347    m_opened = false;
     348
     349    {
     350        MutexLocker locker(guidMutex());
     351
     352        HashSet<Database*>* hashSet = guidToDatabaseMap().get(m_guid);
     353        ASSERT(hashSet);
     354        ASSERT(hashSet->contains(this));
     355        hashSet->remove(this);
     356        if (hashSet->isEmpty()) {
     357            guidToDatabaseMap().remove(m_guid);
     358            delete hashSet;
     359            guidToVersionMap().remove(m_guid);
    357360        }
    358361    }
     362
     363    m_document->databaseThread()->unscheduleDatabaseTasks(this);
     364
     365    DatabaseTracker::tracker().removeOpenDatabase(this);
     366    ref();  // deref() called in documentRemoveOpenDatabase()
     367    callOnMainThread(documentRemoveOpenDatabase, this);
    359368}
    360369
Note: See TracChangeset for help on using the changeset viewer.