void ThumbnailGenerator::run() { LOG(""); while (!testCancel()) { QString pixPath; int pixelSize; { QMutexLocker lock(&mMutex); // empty mPixPath means nothing to do LOG("Waiting for mPixPath"); if (mPixPath.isNull()) { LOG("mPixPath.isNull"); mCond.wait(&mMutex); } } if (testCancel()) { return; } { QMutexLocker lock(&mMutex); pixPath = mPixPath; pixelSize = ThumbnailGroup::pixelSize(mThumbnailGroup); } Q_ASSERT(!pixPath.isNull()); LOG("Loading" << pixPath); ThumbnailContext context; bool ok = context.load(pixPath, pixelSize); { QMutexLocker lock(&mMutex); if (ok) { mImage = context.mImage; mOriginalWidth = context.mOriginalWidth; mOriginalHeight = context.mOriginalHeight; if (context.mNeedCaching) { cacheThumbnail(); } } else { kWarning() << "Could not generate thumbnail for file" << mOriginalUri; } mPixPath.clear(); // done, ready for next } if (testCancel()) { return; } { QSize size(mOriginalWidth, mOriginalHeight); LOG("emitting done signal, size=" << size); QMutexLocker lock(&mMutex); done(mImage, size); LOG("Done"); } } LOG("Ending thread"); }
extern "C" int main(int argc, char *argv[]) { vtimer = sceKernelCreateVTimer("cancel", NULL); testCancel("Normal", vtimer); testCancel("Twice", vtimer); testCancel("NULL", 0); testCancel("Invalid", 0xDEADBEEF); sceKernelDeleteVTimer(vtimer); testCancel("Deleted", vtimer); vtimer = sceKernelCreateVTimer("delete", NULL); sceKernelStartVTimer(vtimer); testCancel("Started", vtimer); sceKernelSetVTimerHandlerWide(vtimer, 1, &basicHandler, (void *)0xABCD1337); testCancel("With handler", vtimer); SceKernelSysClock t = {1, 0}; sceKernelSetVTimerHandler(vtimer, &t, &cancelHandler, (void *)0xABCD1337); sceKernelDelayThread(1000); testCancel("After cancel handler", vtimer); sceKernelSetVTimerHandlerWide(vtimer, 1, &zeroHandler, (void *)0xABCD1337); sceKernelDelayThread(1000); schedfVTimer(vtimer); testCancel("After return zero handler", vtimer); return 0; }
void KernelRenderThread::run() { do { if (_done) break; _kernelRender->renderStep(); } while (!testCancel() && !_done); }
void ThumbnailThread::run() { LOG(""); while (!testCancel()) { { QMutexLocker lock(&mMutex); // empty mPixPath means nothing to do LOG("Waiting for mPixPath"); if (mPixPath.isNull()) { LOG("mPixPath.isNull"); mCond.wait(&mMutex); } } if (testCancel()) { return; } { QMutexLocker lock(&mMutex); Q_ASSERT(!mPixPath.isNull()); LOG("Loading" << mPixPath); bool needCaching; bool ok = loadThumbnail(&needCaching); if (ok && needCaching) { cacheThumbnail(); } mPixPath.clear(); // done, ready for next } if (testCancel()) { return; } { QSize size(mOriginalWidth, mOriginalHeight); LOG("emitting done signal, size=" << size); QMutexLocker lock(&mMutex); done(mImage, size); LOG("Done"); } } LOG("Ending thread"); }
void NavigationDataReceiver::run() { std::cout << "NavigationDataReceiver started\n"; int cnt = 0; try { myCommunicationChannel.connectWithDroneAtAddress(myDroneAddress.c_str(), NAVIGATION_DATA_PORT); myCommunicationChannel.setTimeout(3000); unsigned char trigger[4] = {0x01, 0x00, 0x00, 0x00}; myCommunicationChannel.send(trigger, 4); unsigned char navDataDemo[NAVDATA_DEMO_BUFFER_SIZE]; unsigned int navDataLength = NAVDATA_DEMO_BUFFER_SIZE; while(false == testCancel()) { try { myController->requestNavigationData(DEMO); myCommunicationChannel.receive(navDataDemo, navDataLength); cnt++; if(cnt >= 5) { cnt =0; synchronized(myMutex) { MemoryLibrary::Buffer navDataBuffer(navDataDemo, navDataLength); parse(navDataBuffer); navTimestamp = (long)(seconds() * 1000.0); } } } catch (ccxx::TimeoutException& timeoutEx) { std::cout << "NavigationDataReceiver TIMEOUT exception thrown.." << timeoutEx.what() << std::endl; } catch (ccxx::Exception& ex) { std::cout << "NavigationDataReceiver exception thrown.." << ex.what() << std::endl; } }//while } catch (ccxx::Exception& ex) { std::cout << "NavigationDataReceiver exception thrown.." << ex.what() << std::endl; } std::cout << "NavigationDataReceiver stopped\n"; }
void TL_SocketEventManager::run_I() throw() { TL_Log::Instance().setThreadLogFileName("EventManager"); _p->initThreads(*this); TL_EPollServer::EventsListType *events=NULL; TL_EPollServer::EventsListType *conns=NULL; int loops = 0; for(;;) { if(testCancel()) { break; } conns = TL_EventBuffer::getNewConnections(); if(conns) { loops = 0; _p->passNewClientsToGroups(conns); } events = TL_EventBuffer::getEvents(); if(events) { loops = 0; // pass events to threads _p->passEventsToGroups(events); } else { if(loops > 10) { usleep(1000); // 1 milisecond } else if(loops > 2) { usleep(10); // 10 microsecond loops++; } else { loops++; } } } }
void CRenderingThread::run() { if ( !_ptr ) { _done = true; return; } osgViewer::Viewer* viewer = _ptr->getViewer(); do { _ptr->PreFrameUpdate(); viewer->frame(); _ptr->PostFrameUpdate(); } while ( !testCancel() && !viewer->done() && !_done ); }
virtual void run() { do { if (_image->_active) { int i=WaitForMessage(_client,5000); if(i<0) return; if(i) { osg::notify(osg::NOTICE)<<"Handling "<<i<<" messages"<<std::endl; if(!HandleRFBServerMessage(_client)) return; _image->updated(); } } else { _image->_inactiveBlock->block(); } double deltaTime = _image->getTimeOfLastRender() - _image->getTimeOfLastUpdate(); if (deltaTime<-0.01) { //osg::notify(osg::NOTICE)<<"Inactive"<<std::endl; //_image->_active = false; } else { _image->_active = true; } } while (!_done && !testCancel()); }
virtual void run() { do { // OSG_NOTICE<<"RfThread::run()"<<std::endl; int i=WaitForMessage(_client,1000000); if (i) { if(!HandleRFBServerMessage(_client)) { OSG_NOTICE<<"HandleRFBServerMessage returned non zero value."<<std::endl; } // _image->updated(); } else { // OSG_NOTICE<<"Timed out"<<std::endl; } double currentTime = _image->time(); double timeBeforeIdle = 0.1; if (currentTime > _image->getTimeOfLastRender()+timeBeforeIdle) { //OSG_NOTICE<<"New: Time to idle"<<std::endl; _image->_inactiveBlock->reset(); _image->_inactiveBlock->block(); //OSG_NOTICE<<" Finished block."<<std::endl; } else { //OSG_NOTICE<<"New: Should still be active"<<std::endl; } } while (!_done && !testCancel()); }