From 0d37582e30ccdfc5c1e8da75c8071f620e3b7685 Mon Sep 17 00:00:00 2001 From: Shawn Wilsher Date: Thu, 19 Nov 2009 11:49:20 -0800 Subject: [PATCH] Bug 525356 - windows debug unit tests: test_connection_executeAsync.js and test_statement_executeAsync.js failing frequently (fatal assertion) Release on the calling thread so when the connections destructor is called, it is not on the background thread. r=asuth --- storage/src/mozStorageStatement.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/storage/src/mozStorageStatement.cpp b/storage/src/mozStorageStatement.cpp index 1036a1f28e7..2ea2f94fcda 100644 --- a/storage/src/mozStorageStatement.cpp +++ b/storage/src/mozStorageStatement.cpp @@ -43,6 +43,7 @@ #include "nsError.h" #include "nsMemory.h" +#include "nsProxyRelease.h" #include "nsThreadUtils.h" #include "nsIClassInfoImpl.h" #include "nsIProgrammingLanguage.h" @@ -77,18 +78,33 @@ namespace { class AsyncStatementFinalizer : public nsRunnable { public: - AsyncStatementFinalizer(sqlite3_stmt *aStatement) + /** + * Constructor for the event. + * + * @param aStatement + * The sqlite3_stmt to finalize on the background thread. + * @param aParent + * The object that owns aStatement. It will be released on the calling + * thread. + */ + AsyncStatementFinalizer(sqlite3_stmt *aStatement, + nsISupports *aParent) : mStatement(aStatement) + , mParent(aParent) + , mCallingThread(do_GetCurrentThread()) { } NS_IMETHOD Run() { (void)::sqlite3_finalize(mStatement); + (void)::NS_ProxyRelease(mCallingThread, mParent); return NS_OK; } private: sqlite3_stmt *mStatement; + nsCOMPtr mParent; + nsCOMPtr mCallingThread; }; } // anonymous namespace @@ -401,7 +417,7 @@ Statement::Finalize() } else { nsCOMPtr event = - new AsyncStatementFinalizer(mCachedAsyncStatement); + new AsyncStatementFinalizer(mCachedAsyncStatement, this); NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY); nsresult rv = target->Dispatch(event, NS_DISPATCH_NORMAL);