bool WorkerRunnable::Dispatch(JSContext* aCx) { bool ok; if (!aCx) { ok = PreDispatch(nullptr, mWorkerPrivate); if (ok) { ok = DispatchInternal(); } PostDispatch(nullptr, mWorkerPrivate, ok); return ok; } JSAutoRequest ar(aCx); JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx)); Maybe<JSAutoCompartment> ac; if (global) { ac.emplace(aCx, global); } ok = PreDispatch(aCx, mWorkerPrivate); if (ok && !DispatchInternal()) { ok = false; } PostDispatch(aCx, mWorkerPrivate, ok); return ok; }
NS_IMETHODIMP LazyIdleThread::Dispatch(already_AddRefed<nsIRunnable> aEvent, uint32_t aFlags) { ASSERT_OWNING_THREAD(); nsCOMPtr<nsIRunnable> event(aEvent); // avoid leaks // LazyIdleThread can't always support synchronous dispatch currently. if (NS_WARN_IF(aFlags != NS_DISPATCH_NORMAL)) { return NS_ERROR_NOT_IMPLEMENTED; } if (NS_WARN_IF(mShutdown)) { return NS_ERROR_UNEXPECTED; } // If our thread is shutting down then we can't actually dispatch right now. // Queue this runnable for later. if (UseRunnableQueue()) { mQueuedRunnables->AppendElement(event); return NS_OK; } nsresult rv = EnsureThread(); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } PreDispatch(); return mThread->Dispatch(event.forget(), aFlags); }
NS_IMETHODIMP LazyIdleThread::Dispatch(nsIRunnable* aEvent, uint32_t aFlags) { ASSERT_OWNING_THREAD(); // LazyIdleThread can't always support synchronous dispatch currently. if (NS_WARN_IF(aFlags != NS_DISPATCH_NORMAL)) return NS_ERROR_NOT_IMPLEMENTED; // If our thread is shutting down then we can't actually dispatch right now. // Queue this runnable for later. if (UseRunnableQueue()) { mQueuedRunnables->AppendElement(aEvent); return NS_OK; } nsresult rv = EnsureThread(); if (NS_WARN_IF(NS_FAILED(rv))) return rv; PreDispatch(); return mThread->Dispatch(aEvent, aFlags); }
bool WorkerRunnable::Dispatch() { bool ok = PreDispatch(mWorkerPrivate); if (ok) { ok = DispatchInternal(); } PostDispatch(mWorkerPrivate, ok); return ok; }
EFI_STATUS ResumeExecComd ( VOID ) /*++ Routine Description: Resume SCT execution by executing "sct -c" in sct passive mode. Arguments: None Returns: EFI_SUCCESS - Operation succeeded. EFI_OUT_OF_RESOURCES - Memory allocation failed. Others - Some failure happened. --*/ { EFI_STATUS Status; EFI_TIME StartTime; EFI_TIME EndTime; CHAR16 *Buffer; Buffer = EFI_SCT_CONTINUE_EXECUTION_NAME; // // PreDispatch: to get cmd and parameters // Status = PreDispatch (Buffer); if (EFI_ERROR (Status)) { (gEasFT->Cmd)->ComdResult = FAIL; EFI_ENTS_DEBUG ((EFI_ENTS_D_ERROR, L"Error in ResumeExecComd: PreDispatch error - %r", Status)); Status = PostDispatch (); if (EFI_ERROR (Status)) { EFI_ENTS_DEBUG ((EFI_ENTS_D_ERROR, L"Error in ResumeExecComd: PostDispatch status - %r\n", Status)); } return Status; } // // Resume SCT execution by executing "sct -c" in sct passive mode. // RT->GetTime (&StartTime, NULL); Status = ShellExecute (mImageHandle, (gEasFT->Cmd)->ComdArg, FALSE); RT->GetTime (&EndTime, NULL); EFI_ENTS_DEBUG ((EFI_ENTS_D_TRACE, L"dispatch:(%s)", (gEasFT->Cmd)->ComdArg)); Print (L"dispatch:(%s) - %r\n", (gEasFT->Cmd)->ComdArg, Status); if (Status == EFI_OUT_OF_RESOURCES) { return EFI_OUT_OF_RESOURCES; } Status = RecordMessage ( &((gEasFT->Cmd)->ComdRuntimeInfo), &(gEasFT->Cmd)->ComdRuntimeInfoSize, L"TEST_EXEC (%s) Status - %r", (gEasFT->Cmd)->ComdArg, Status ); if (Status == EFI_OUT_OF_RESOURCES) { return EFI_OUT_OF_RESOURCES; } Status = RecordMessage ( &((gEasFT->Cmd)->ComdOutput), &(gEasFT->Cmd)->ComdOutputSize, L"StartTime - %02d-%02d-%04d %02d:%02d:%02d, EndTime - %02d-%02d-%04d %02d:%02d:%02d", StartTime.Day, StartTime.Month, StartTime.Year, StartTime.Hour, StartTime.Minute, StartTime.Second, EndTime.Day, EndTime.Month, EndTime.Year, EndTime.Hour, EndTime.Minute, EndTime.Second ); if (Status == EFI_OUT_OF_RESOURCES) { return EFI_OUT_OF_RESOURCES; } // // For remote SCT execution, the potential reset during the execution will cause no ACK generation, so // after "sct -c" execution finish, corresponding ACK needs to be sent to inform remote EMS side application. // Status = PostDispatch (); if (EFI_ERROR (Status)) { EFI_ENTS_DEBUG ((EFI_ENTS_D_ERROR, L"Error in ResumeExecComd: PostDispatch status - %r\n", Status)); } return Status; }
nsresult LazyIdleThread::ShutdownThread() { ASSERT_OWNING_THREAD(); // Before calling Shutdown() on the real thread we need to put a queue in // place in case a runnable is posted to the thread while it's in the // process of shutting down. This will be our queue. nsAutoTArray<nsCOMPtr<nsIRunnable>, 10> queuedRunnables; nsresult rv; if (mThread) { if (mShutdownMethod == AutomaticShutdown && NS_IsMainThread()) { nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService(); NS_WARN_IF_FALSE(obs, "Failed to get observer service!"); if (obs && NS_FAILED(obs->RemoveObserver(this, "xpcom-shutdown-threads"))) { NS_WARNING("Failed to remove observer!"); } } if (mIdleObserver) { mIdleObserver->Observe(static_cast<nsIThread*>(this), IDLE_THREAD_TOPIC, nullptr); } #ifdef DEBUG { MutexAutoLock lock(mMutex); MOZ_ASSERT(!mThreadIsShuttingDown, "Huh?!"); } #endif nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableMethod(this, &LazyIdleThread::CleanupThread); NS_ENSURE_TRUE(runnable, NS_ERROR_FAILURE); PreDispatch(); rv = mThread->Dispatch(runnable, NS_DISPATCH_NORMAL); NS_ENSURE_SUCCESS(rv, rv); // Put the temporary queue in place before calling Shutdown(). mQueuedRunnables = &queuedRunnables; if (NS_FAILED(mThread->Shutdown())) { NS_ERROR("Failed to shutdown the thread!"); } // Now unset the queue. mQueuedRunnables = nullptr; mThread = nullptr; { MutexAutoLock lock(mMutex); MOZ_ASSERT(!mPendingEventCount, "Huh?!"); MOZ_ASSERT(!mIdleNotificationCount, "Huh?!"); MOZ_ASSERT(mThreadIsShuttingDown, "Huh?!"); mThreadIsShuttingDown = false; } } if (mIdleTimer) { rv = mIdleTimer->Cancel(); NS_ENSURE_SUCCESS(rv, rv); mIdleTimer = nullptr; } // If our temporary queue has any runnables then we need to dispatch them. if (queuedRunnables.Length()) { // If the thread manager has gone away then these runnables will never run. if (mShutdown) { NS_ERROR("Runnables dispatched to LazyIdleThread will never run!"); return NS_OK; } // Re-dispatch the queued runnables. for (uint32_t index = 0; index < queuedRunnables.Length(); index++) { nsCOMPtr<nsIRunnable> runnable; runnable.swap(queuedRunnables[index]); MOZ_ASSERT(runnable, "Null runnable?!"); if (NS_FAILED(Dispatch(runnable, NS_DISPATCH_NORMAL))) { NS_ERROR("Failed to re-dispatch queued runnable!"); } } } return NS_OK; }