/* to take over. */ void E2FilterIORB (PIORB pIORB) { NPRecHeader pUnitRec; /* Ptr to unit rec for IORB */ NPIORBQueue pQueue; /* Ptr to queue for IORB */ if (pIORB->CommandCode==IOCC_CONFIGURATION) /* For configuration IORBs: */ pUnitRec= (NPRecHeader) VirtUnits; /* Assign IORB to the first */ /* virtual unit. (For queue) */ else pUnitRec= (NPRecHeader) pIORB->UnitHandle; /* Get pointer to unit */ /* from the unit handle */ /* Check to see if pUnitRec is a pointer to a valid unit record. */ if (!(IS_ELEMENT(pUnitRec,BaseUnits,NumBaseUnits)|| IS_ELEMENT(pUnitRec,VirtUnits,NumVirtUnits))) { IORBError (pIORB,IOERR_NO_SUCH_UNIT); /* Tell them they are crazy! */ NotifyDone (pIORB); /* Notify that we are done */ } else { pQueue= &(pUnitRec->IORBQueue); /* Get pointer to IORB queue */ DISABLE /* Same safety... */ AddIORBToQueue (pQueue,pIORB); /* Add IORB to queue */ ENABLE /* Re-enable interrupts */ StartIORBQueue (pQueue); /* Try to restart the queue */ } }
NS_IMETHODIMP nsDOMWorkerScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext, nsresult aStatus, PRUint32 aStringLen, const PRUint8* aString) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); // We may have been canceled already. if (mCanceled) { return NS_BINDING_ABORTED; } nsresult rv = OnStreamCompleteInternal(aLoader, aContext, aStatus, aStringLen, aString); // Dispatch the done event if we've received all the data. for (PRUint32 index = 0; index < mScriptCount; index++) { if (!mLoadInfos[index].done) { // Some async load is still outstanding, don't notify yet. break; } if (index == mScriptCount - 1) { // All loads complete, signal the thread. NotifyDone(); } } return rv; }
/* the IORB queue. */ void PartCommandDone (NPVirtUnitRec pUnitRec, PIORB pIORB) { NPIORBQueue pQueue; /* Pointer to IORB queue */ pQueue= &(pUnitRec->Hdr.IORBQueue); /* Get pointer to queue */ pQueue->Flags&=~F_REQUEST_BUSY; /* Indicate queue finished */ NotifyDone (pIORB); /* Notify caller */ StartIORBQueue (pQueue); /* Try to restart queue */ }
nsresult nsIconDecoder::FinishInternal() { // If we haven't notified of completion yet for a full/success decode, we // didn't finish. Notify in error mode if (!IsSizeDecode() && !mNotifiedDone) NotifyDone(/* aSuccess = */ PR_FALSE); return NS_OK; }
NS_IMETHODIMP nsDOMWorkerScriptLoader::Run() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); // We may have been canceled already. if (mCanceled) { return NS_BINDING_ABORTED; } nsresult rv = RunInternal(); if (NS_SUCCEEDED(rv)) { return rv; } // Ok, something failed beyond a normal cancel. // If necko is holding a ref to us then we'll end up notifying in the // OnStreamComplete method, not here. PRBool needsNotify = PR_TRUE; // Cancel any async channels that were already opened. for (PRUint32 index = 0; index < mScriptCount; index++) { ScriptLoadInfo& loadInfo = mLoadInfos[index]; nsIRequest* request = static_cast<nsIRequest*>(loadInfo.channel.get()); if (request) { #ifdef DEBUG nsresult rvInner = #endif request->Cancel(NS_BINDING_ABORTED); NS_WARN_IF_FALSE(NS_SUCCEEDED(rvInner), "Failed to cancel channel!"); // Necko is holding a ref to us so make sure that the OnStreamComplete // code sends the done event. needsNotify = PR_FALSE; } else { // Make sure to set this so that the OnStreamComplete code will dispatch // the done event. loadInfo.done = PR_TRUE; } } if (needsNotify) { NotifyDone(); } return rv; }
/* restored before we pass it back to the original caller. */ void FilterNotify (PIORB pIORB) { NPBaseUnitRec pUnitRec; /* Ptr to unit record */ NPIORBQueue pQueue; /* Queue request came from */ pUnitRec= (NPBaseUnitRec) pIORB->Reserved_1; /* Get ptr to unit record */ pIORB->UnitHandle= (USHORT) pUnitRec; /* Restore old unit handle */ pIORB->RequestControl= pUnitRec->SaveReqCtrl; /* Restore rest of IORB */ pIORB->Reserved_1= pUnitRec->SaveReserved; pIORB->NotifyAddress= pUnitRec->SaveNotify; pQueue= &(pUnitRec->Hdr.IORBQueue); /* Get ptr to IORB queue */ pQueue->Flags&=~F_REQUEST_BUSY; /* Indicate queue finished */ NotifyDone (pIORB); /* Notify caller */ StartIORBQueue (pQueue); /* Try to restart queue */ }
void nsDOMWorkerScriptLoader::Cancel() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(!mCanceled, "Cancel called more than once!"); mCanceled = PR_TRUE; for (PRUint32 index = 0; index < mScriptCount; index++) { ScriptLoadInfo& loadInfo = mLoadInfos[index]; nsIRequest* request = static_cast<nsIRequest*>(loadInfo.channel.get()); if (request) { #ifdef DEBUG nsresult rv = #endif request->Cancel(NS_BINDING_ABORTED); NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to cancel channel!"); } } nsAutoTArray<ScriptLoaderRunnable*, 10> runnables; { nsAutoLock lock(mWorker->Lock()); runnables.AppendElements(mPendingRunnables); mPendingRunnables.Clear(); } PRUint32 runnableCount = runnables.Length(); for (PRUint32 index = 0; index < runnableCount; index++) { runnables[index]->Revoke(); } // We're about to post a revoked event to the worker thread, which seems // silly, but we have to do this because the worker thread may be sleeping // waiting on its event queue. NotifyDone(); }
bool URLRequestQrcJobQt::ReadRawData(IOBuffer *buf, int bufSize, int *bytesRead) { DCHECK(bytesRead); DCHECK_GE(m_remainingBytes, 0); // File has been read finished. if (!m_remainingBytes || !bufSize) { *bytesRead = 0; return true; } if (m_remainingBytes < bufSize) bufSize = static_cast<int>(m_remainingBytes); qint64 rv = m_file.read(buf->data(), bufSize); if (rv >= 0) { *bytesRead = static_cast<int>(rv); m_remainingBytes -= rv; DCHECK_GE(m_remainingBytes, 0); return true; } else { NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, ERR_FAILED)); } return false; }
/* being serviced before entering the service loop. */ void StartIORBQueue (NPIORBQueue pQueue) { PIORB pIORB; /* Ptr to IORB to execute */ NPRecHeader pUnitRec; /* Pointer to unit record */ DISABLE if (!(pQueue->Flags&F_SERVER_ACTIVE)) /* Check to no one is busy */ /* servicing this queue */ { pQueue->Flags|=F_SERVER_ACTIVE; /* Grap control of queue */ /* If we get where we have exclusize access to the queue. */ while ((!(pQueue->Flags&F_REQUEST_BUSY))&& ((pIORB= GetIORBFromQueue (pQueue))!=NULL)) /* Loop while there is an */ /* IORB ready to be serviced */ /* and the previous IORB is */ /* finished. */ { pQueue->Flags|=F_REQUEST_BUSY; /* Show request in progress */ ENABLE if (pIORB->CommandCode==IOCC_CONFIGURATION) /* For configuration IORBs: */ pUnitRec= (NPRecHeader) VirtUnits; /* Assign IORB to the first */ /* virtual unit. (For queue) */ else pUnitRec= (NPRecHeader) pIORB->UnitHandle; /* Get pointer to unit */ /* from the unit handle */ /* We will handle (de)allocation and allocation checks here since it is */ /* common between the two parts- filter and virtual units. */ if (pIORB->CommandCode==IOCC_UNIT_CONTROL) /* Unit control command? */ { if (pIORB->CommandModifier==IOCM_ALLOCATE_UNIT) { /* Allocate unit??? */ if (pUnitRec->Flags&F_ALLOCATED) IORBError (pIORB,IOERR_UNIT_ALLOCATED); /* Error if allocated */ else pUnitRec->Flags|=F_ALLOCATED; /* Else allocate the unit */ pQueue->Flags&=~F_REQUEST_BUSY; /* Indicate queue finished */ NotifyDone (pIORB); continue; /* Service next request */ } if (pIORB->CommandModifier==IOCM_DEALLOCATE_UNIT) { /* Deallocate unit??? */ if (!(pUnitRec->Flags&F_ALLOCATED)) IORBError (pIORB,IOERR_UNIT_NOT_ALLOCATED); /* Error if not allocated */ else pUnitRec->Flags&=~F_ALLOCATED; /* Else deallocate unit */ pQueue->Flags&=~F_REQUEST_BUSY; /* Indicate queue finished */ NotifyDone (pIORB); continue; /* Service next request */ } } /* Do allocations checks... if notify points to us, skip check. */ if (!(pUnitRec->Flags&F_ALLOCATED)) /* If unit is not allocated: */ if (pIORB->NotifyAddress!=&PartNotifyWrapper) /* and we didn't make request */ if (pIORB->CommandCode!=IOCC_CONFIGURATION) /* and not configuration */ { IORBError (pIORB,IOERR_UNIT_NOT_ALLOCATED); /* Then it is an error */ pQueue->Flags&=~F_REQUEST_BUSY; /* Indicate queue finished */ NotifyDone (pIORB); continue; /* Service next request */ } if (IS_ELEMENT(pUnitRec,BaseUnits,NumBaseUnits)) FilterHandler (pIORB); /* Handler for base units */ else if (IS_ELEMENT(pUnitRec,VirtUnits,NumVirtUnits)) PartHandler (pIORB); /* Handler for virtual units */ DISABLE } /* Tell others that this server is not active any more... */ pQueue->Flags&=~F_SERVER_ACTIVE; }
nsresult nsIconDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount) { nsresult rv; // We put this here to avoid errors about crossing initialization with case // jumps on linux. PRUint32 bytesToRead = 0; // Performance isn't critical here, so our update rectangle is // always the full icon nsIntRect r(0, 0, mWidth, mHeight); // Loop until the input data is gone while (aCount > 0) { switch (mState) { case iconStateStart: // Grab the width mWidth = (PRUint8)*aBuffer; // Book Keeping aBuffer++; aCount--; mState = iconStateHaveHeight; break; case iconStateHaveHeight: // Grab the Height mHeight = (PRUint8)*aBuffer; // Post our size to the superclass PostSize(mWidth, mHeight); // If We're doing a size decode, we're done if (IsSizeDecode()) { mState = iconStateFinished; break; } // Add the frame and signal rv = mImage->AppendFrame(0, 0, mWidth, mHeight, gfxASurface::ImageFormatARGB32, &mImageData, &mPixBytesTotal); if (NS_FAILED(rv)) { mState = iconStateError; return rv; } // Tell the superclass we're starting a frame PostFrameStart(); // Book Keeping aBuffer++; aCount--; mState = iconStateReadPixels; break; case iconStateReadPixels: // How many bytes are we reading? bytesToRead = PR_MIN(aCount, mPixBytesTotal - mPixBytesRead); // Copy the bytes memcpy(mImageData + mPixBytesRead, aBuffer, bytesToRead); // Invalidate PostInvalidation(r); // Book Keeping aBuffer += bytesToRead; aCount -= bytesToRead; mPixBytesRead += bytesToRead; // If we've got all the pixel bytes, we're finished if (mPixBytesRead == mPixBytesTotal) { NotifyDone(/* aSuccess = */ PR_TRUE); mState = iconStateFinished; } break; case iconStateFinished: // Consume all excess data silently aCount = 0; break; case iconStateError: return NS_IMAGELIB_ERROR_FAILURE; break; } } return NS_OK; }