void CachePushStreamChild::DoRead() { NS_ASSERT_OWNINGTHREAD(CachePushStreamChild); MOZ_ASSERT(!mClosed); MOZ_ASSERT(!mCallback); // The input stream (likely a pipe) probably uses a segment size of // 4kb. If there is data already buffered it would be nice to aggregate // multiple segments into a single IPC call. Conversely, don't send too // too large of a buffer in a single call to avoid spiking memory. static const uint64_t kMaxBytesPerMessage = 32 * 1024; static_assert(kMaxBytesPerMessage <= static_cast<uint64_t>(UINT32_MAX), "kMaxBytesPerMessage must cleanly cast to uint32_t"); while (!mClosed) { // Use non-auto here as we're unlikely to hit stack storage with the // sizes we are sending. Also, it would be nice to avoid another copy // to the IPC layer which we avoid if we use COW strings. Unfortunately // IPC does not seem to support passing dependent storage types. nsCString buffer; uint64_t available = 0; nsresult rv = mStream->Available(&available); if (NS_FAILED(rv)) { OnEnd(rv); return; } if (available == 0) { Wait(); return; } uint32_t expectedBytes = static_cast<uint32_t>(std::min(available, kMaxBytesPerMessage)); buffer.SetLength(expectedBytes); uint32_t bytesRead = 0; rv = mStream->Read(buffer.BeginWriting(), buffer.Length(), &bytesRead); buffer.SetLength(bytesRead); // If we read any data from the stream, send it across. if (!buffer.IsEmpty()) { Unused << SendBuffer(buffer); } if (rv == NS_BASE_STREAM_WOULD_BLOCK) { Wait(); return; } // Any other error or zero-byte read indicates end-of-stream if (NS_FAILED(rv) || buffer.IsEmpty()) { OnEnd(rv); return; } } }
//-------------------------------------------------------------------------- void VeJob::End(bool bSuccess) noexcept { VeVector<VeJobPtr> kRelatedJobs; { std::lock_guard<vtd::spin_lock> lock(m_kLock); VE_ASSERT(!m_u32Wait); m_u32Pointer = 0; kRelatedJobs = std::move(m_kRelatedJobs); } if (bSuccess) { for (auto& job : kRelatedJobs) { job->Resume(); } } else { for (auto& job : kRelatedJobs) { job->End(false); } } OnEnd(bSuccess); DecRefCount(); }
void IAudioSource::FireEndEvent() { if (!mIsEnd) { IEventArg e=IEventArg::Empty; OnEnd(*this,e); mIsEnd=true; } }
StateMachine::~StateMachine() { for (MapStateList::const_iterator iter = m_mapStateList.begin(); iter != m_mapStateList.end(); ++iter) { SAFE_DEL(iter->second) } m_mapStateList.clear(); m_pCurState = nullptr; SAFE_DEL(m_pCallbackProtocol); OnEnd(); }
void CachePushStreamChild::Wait() { NS_ASSERT_OWNINGTHREAD(CachePushStreamChild); MOZ_ASSERT(!mClosed); MOZ_ASSERT(!mCallback); // Set mCallback immediately instead of waiting for success. Its possible // AsyncWait() will callback synchronously. mCallback = new Callback(this); nsresult rv = mStream->AsyncWait(mCallback, 0, 0, nullptr); if (NS_FAILED(rv)) { OnEnd(rv); return; } }
//--------------------------------------------------------------------------- CATResult CATApp::Run() { CATResult result = CAT_SUCCESS; result = OnStart(); // If starting failed, then bail without entering main loop. if (CATFAILED(result)) { return result; } result = MainLoop(); // Pass the result from the MainLoop into OnEnd. result = OnEnd(result); return result; }
//-------------------------------------------------------------------------------------- // Desc: //-------------------------------------------------------------------------------------- LRESULT CD3DArcBall::HandleMessages( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { // Current mouse position int iMouseX = ( short )LOWORD( lParam ); int iMouseY = ( short )HIWORD( lParam ); switch( uMsg ) { case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: SetCapture( hWnd ); OnBegin( iMouseX, iMouseY ); return TRUE; case WM_LBUTTONUP: ReleaseCapture(); OnEnd(); return TRUE; case WM_CAPTURECHANGED: if( ( HWND )lParam != hWnd ) { ReleaseCapture(); OnEnd(); } return TRUE; case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: SetCapture( hWnd ); // Store off the position of the cursor when the button is pressed m_ptLastMouse.x = iMouseX; m_ptLastMouse.y = iMouseY; return TRUE; case WM_RBUTTONUP: case WM_MBUTTONUP: ReleaseCapture(); return TRUE; case WM_MOUSEMOVE: if( MK_LBUTTON & wParam ) { OnMove( iMouseX, iMouseY ); } else if( ( MK_RBUTTON & wParam ) || ( MK_MBUTTON & wParam ) ) { // Normalize based on size of window and bounding sphere radius FLOAT fDeltaX = ( m_ptLastMouse.x - iMouseX ) * m_fRadiusTranslation / m_nWidth; FLOAT fDeltaY = ( m_ptLastMouse.y - iMouseY ) * m_fRadiusTranslation / m_nHeight; if( wParam & MK_RBUTTON ) { D3DXMatrixTranslation( &m_mTranslationDelta, -2 * fDeltaX, 2 * fDeltaY, 0.0f ); D3DXMatrixMultiply( &m_mTranslation, &m_mTranslation, &m_mTranslationDelta ); } else // wParam & MK_MBUTTON { D3DXMatrixTranslation( &m_mTranslationDelta, 0.0f, 0.0f, 5 * fDeltaY ); D3DXMatrixMultiply( &m_mTranslation, &m_mTranslation, &m_mTranslationDelta ); } // Store mouse coordinate m_ptLastMouse.x = iMouseX; m_ptLastMouse.y = iMouseY; } return TRUE; } return FALSE; }