本文整理汇总了C++中TransactionThreadPool类的典型用法代码示例。如果您正苦于以下问题:C++ TransactionThreadPool类的具体用法?C++ TransactionThreadPool怎么用?C++ TransactionThreadPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TransactionThreadPool类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NS_ASSERTION
nsresult
IDBTransaction::CommitOrRollback()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
if (!IndexedDatabaseManager::IsMainProcess()) {
NS_ASSERTION(mActorChild, "Must have an actor!");
mActorChild->SendAllRequestsFinished();
return NS_OK;
}
nsRefPtr<CommitHelper> helper =
new CommitHelper(this, mListener, mCreatedObjectStores);
TransactionThreadPool* pool = TransactionThreadPool::GetOrCreate();
NS_ENSURE_STATE(pool);
mCachedStatements.Enumerate(DoomCachedStatements, helper);
NS_ASSERTION(!mCachedStatements.Count(), "Statements left!");
nsresult rv = pool->Dispatch(this, helper, true, helper);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
示例2: NS_ASSERTION
NS_IMETHODIMP
TransactionPoolEventTarget::Dispatch(nsIRunnable* aRunnable,
PRUint32 aFlags)
{
NS_ASSERTION(aRunnable, "Null pointer!");
NS_ASSERTION(aFlags == NS_DISPATCH_NORMAL, "Unsupported!");
TransactionThreadPool* pool = TransactionThreadPool::GetOrCreate();
return pool->Dispatch(mTransaction, aRunnable, false, nsnull);
}
示例3: NS_ASSERTION
void
IndexedDatabaseManager::OnDatabaseClosed(IDBDatabase* aDatabase)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(aDatabase, "Null pointer!");
// Check through the list of SetVersionRunnables we have amassed to see if
// this database is part of a SetVersion callback.
for (PRUint32 index = 0; index < mSetVersionRunnables.Length(); index++) {
nsRefPtr<SetVersionRunnable>& runnable = mSetVersionRunnables[index];
if (runnable->mRequestingDatabase->Id() == aDatabase->Id()) {
// This is the SetVersionRunnable for the given database file. Remove the
// database from the list of databases that need to be closed. Since we
// use this hook for SetVersion requests that don't actually need to wait
// for other databases the mDatabases array may be empty.
if (!runnable->mDatabases.IsEmpty() &&
!runnable->mDatabases.RemoveElement(aDatabase)) {
NS_ERROR("Didn't have this database in our list!");
}
// Now run the helper if there are no more live databases.
if (runnable->mHelper && runnable->mDatabases.IsEmpty()) {
// Don't hold the callback alive longer than necessary.
nsRefPtr<AsyncConnectionHelper> helper;
helper.swap(runnable->mHelper);
if (NS_FAILED(helper->DispatchToTransactionPool())) {
NS_WARNING("Failed to dispatch to thread pool!");
}
// Now wait for the transaction to complete. Completing the transaction
// will be our cue to remove the SetVersionRunnable from our list and
// therefore allow other SetVersion requests to begin.
TransactionThreadPool* pool = TransactionThreadPool::Get();
NS_ASSERTION(pool, "This should never be null!");
// All other databases should be closed, so we only need to wait on this
// one.
nsAutoTArray<nsRefPtr<IDBDatabase>, 1> array;
if (!array.AppendElement(aDatabase)) {
NS_ERROR("This should never fail!");
}
// Use the SetVersionRunnable as the callback.
if (!pool->WaitForAllDatabasesToComplete(array, runnable)) {
NS_WARNING("Failed to wait for transaction to complete!");
}
}
break;
}
}
}
示例4: NS_ASSERTION
bool
Client::HasTransactionsForStorage(nsIOfflineStorage* aStorage)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
TransactionThreadPool* pool = TransactionThreadPool::Get();
NS_ASSERTION(pool, "Should have checked if transaction service is active!");
IDBDatabase* database = IDBDatabase::FromStorage(aStorage);
NS_ASSERTION(database, "This shouldn't be null!");
return pool->HasTransactionsForDatabase(database);
}
示例5: NS_ASSERTION
NS_IMETHODIMP
TransactionPoolEventTarget::Dispatch(nsIRunnable* aRunnable,
uint32_t aFlags)
{
NS_ASSERTION(aRunnable, "Null pointer!");
NS_ASSERTION(aFlags == NS_DISPATCH_NORMAL, "Unsupported!");
TransactionThreadPool* pool = TransactionThreadPool::GetOrCreate();
NS_ENSURE_TRUE(pool, NS_ERROR_UNEXPECTED);
nsresult rv = pool->Dispatch(mTransaction, aRunnable, false, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
示例6: NS_ASSERTION
void
IndexedDatabaseManager::OnDatabaseClosed(IDBDatabase* aDatabase)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(aDatabase, "Null pointer!");
// Check through the list of SynchronizedOps to see if any are waiting for
// this database to close before proceeding.
PRUint32 count = mSynchronizedOps.Length();
for (PRUint32 index = 0; index < count; index++) {
nsAutoPtr<SynchronizedOp>& op = mSynchronizedOps[index];
if (op->mOrigin == aDatabase->Origin() &&
(op->mId == aDatabase->Id() || !op->mId)) {
// This database is in the scope of this SynchronizedOp. Remove it
// from the list if necessary.
if (op->mDatabases.RemoveElement(aDatabase)) {
// Now set up the helper if there are no more live databases.
NS_ASSERTION(op->mHelper, "How did we get rid of the helper before "
"removing the last database?");
if (op->mDatabases.IsEmpty()) {
// At this point, all databases are closed, so no new transactions
// can be started. There may, however, still be outstanding
// transactions that have not completed. We need to wait for those
// before we dispatch the helper.
TransactionThreadPool* pool = TransactionThreadPool::GetOrCreate();
if (!pool) {
NS_ERROR("IndexedDB is totally broken.");
return;
}
nsRefPtr<WaitForTransactionsToFinishRunnable> waitRunnable =
new WaitForTransactionsToFinishRunnable(op);
nsAutoTArray<nsRefPtr<IDBDatabase>, 1> array;
array.AppendElement(aDatabase);
// Use the WaitForTransactionsToFinishRunnable as the callback.
if (!pool->WaitForAllDatabasesToComplete(array, waitRunnable)) {
NS_WARNING("Failed to wait for transaction to complete!");
}
}
break;
}
}
}
}
示例7: NS_ASSERTION
// static
already_AddRefed<IDBTransaction>
IDBTransaction::Create(IDBDatabase* aDatabase,
nsTArray<nsString>& aObjectStoreNames,
Mode aMode,
bool aDispatchDelayed)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
nsRefPtr<IDBTransaction> transaction = new IDBTransaction();
transaction->BindToOwner(aDatabase);
if (!transaction->SetScriptOwner(aDatabase->GetScriptOwner())) {
return nsnull;
}
transaction->mDatabase = aDatabase;
transaction->mMode = aMode;
transaction->mDatabaseInfo = aDatabase->Info();
if (!transaction->mObjectStoreNames.AppendElements(aObjectStoreNames)) {
NS_ERROR("Out of memory!");
return nsnull;
}
if (!transaction->mCachedStatements.Init()) {
NS_ERROR("Failed to initialize hash!");
return nsnull;
}
if (!aDispatchDelayed) {
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
NS_ENSURE_TRUE(appShell, nsnull);
nsresult rv = appShell->RunBeforeNextEvent(transaction);
NS_ENSURE_SUCCESS(rv, nsnull);
transaction->mCreating = true;
}
if (aMode != IDBTransaction::VERSION_CHANGE) {
TransactionThreadPool* pool = TransactionThreadPool::GetOrCreate();
pool->Dispatch(transaction, &gStartTransactionRunnable, false, nsnull);
}
return transaction.forget();
}
示例8: NS_ASSERTION
NS_IMETHODIMP
IDBCursor::Continue(const jsval &aKey,
JSContext* aCx,
PRUint8 aOptionalArgCount,
PRBool* _retval)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
if (!mObjectStore->TransactionIsOpen()) {
return NS_ERROR_UNEXPECTED;
}
if (mContinueCalled) {
return NS_ERROR_NOT_AVAILABLE;
}
Key key;
nsresult rv = IDBObjectStore::GetKeyFromJSVal(aKey, key);
NS_ENSURE_SUCCESS(rv, rv);
if (key.IsNull()) {
if (aOptionalArgCount) {
return NS_ERROR_INVALID_ARG;
}
else {
key = Key::UNSETKEY;
}
}
TransactionThreadPool* pool = TransactionThreadPool::GetOrCreate();
NS_ENSURE_TRUE(pool, NS_ERROR_FAILURE);
nsRefPtr<ContinueRunnable> runnable(new ContinueRunnable(this, key));
rv = pool->Dispatch(mTransaction, runnable, false, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
mTransaction->OnNewRequest();
mContinueCalled = true;
*_retval = PR_TRUE;
return NS_OK;
}
示例9: NS_ASSERTION
nsresult
IDBTransaction::CommitOrRollback()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
TransactionThreadPool* pool = TransactionThreadPool::GetOrCreate();
NS_ENSURE_STATE(pool);
nsRefPtr<CommitHelper> helper(new CommitHelper(this, mListener,
mCreatedObjectStores));
mCachedStatements.Enumerate(DoomCachedStatements, helper);
NS_ASSERTION(!mCachedStatements.Count(), "Statements left!");
nsresult rv = pool->Dispatch(this, helper, true, helper);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}