void ThreadEngineBase::run() // implements QRunnable. { if (this->isCanceled()) { threadExit(); return; } startThreads(); #ifndef QT_NO_EXCEPTIONS try { #endif while (threadFunction() == ThrottleThread) { // threadFunction returning ThrottleThread means it that the user // struct wants to be throttled by making a worker thread exit. // Respect that request unless this is the only worker thread left // running, in which case it has to keep going. if (threadThrottleExit()) return; } #ifndef QT_NO_EXCEPTIONS } catch (QtConcurrent::Exception &e) { handleException(e); } catch (...) { handleException(QtConcurrent::UnhandledException()); } #endif threadExit(); }
static void _thread_begin(void* arg) { Thread t = (Thread)arg; ThreadVars* tv = getThreadVars(); tv->magic = THREADVARS_MAGIC; tv->reent = &t->reent; tv->thread_ptr = t; tv->tls_tp = (u8*)t->stacktop-8; // ARM ELF TLS ABI mandates an 8-byte header t->ep(t->arg); threadExit(0); }
void EmulatorThread::run() { stopped = false; while (!stopped) { c8emu->DoInstruction(); msleep(1); if (c8emu->ScreenIsInvalidated()) { // send signal to UI emit screenInvalidated(); } } emit threadExit(); }
void Screen::run() { #ifdef DEBUG char dbgstr[256]; FILE * dbglog = fopen ("Screen_run.log", "w"); #endif // OK, this routine is a single thread that manages // updating and refreshing the screen. This should // run a maximum of _updatefreq times a second _updatecounter = 0; struct timeval start; struct timeval now; struct timespec due; gettimeofday(&start,NULL); // Immediate update is due due.tv_sec = start.tv_sec; due.tv_nsec = start.tv_usec * 1000; while (!shouldterminate()) { // What time is it? gettimeofday(&now,NULL); #ifdef DEBUG fprintf(dbglog, "Now %d:%09d Due %d:%09d\n", (int) now.tv_sec, (int) now.tv_usec * 1000, (int) due.tv_sec, (int) due.tv_nsec); #endif // Are we due for an update? if ((now.tv_sec > due.tv_sec) || ((now.tv_sec == due.tv_sec) && (now.tv_usec * 1000 > due.tv_nsec))) { // Yes, so calc when next update's due //due.tv_sec = now.tv_sec + _updateperiod.tv_sec; //due.tv_nsec = now.tv_usec * 1000 + _updateperiod.tv_nsec; due.tv_sec += _updateperiod.tv_sec; due.tv_nsec += _updateperiod.tv_nsec; if (due.tv_nsec >= 1000000000) { due.tv_nsec -= 1000000000; due.tv_sec++; } // Update the counter if (++_updatecounter >= MAX_SCREEN_CYCLE) _updatecounter = 0; #ifdef DEBUG move (_maxy-1,0); sprintf (dbgstr,"%d",_updatecounter); addstr (dbgstr); #endif // fire off the refresh refresh(); } // Go through the artifact list and do any work // that's available in this update for (std::vector<Artifact *>::iterator Aitr = _artifactList.begin(); Aitr != _artifactList.end(); Aitr++) { (*Aitr)->render(this); } // Now check to see if there are any characters // that need to be sent to the client int newchar; while ((newchar = wgetch(_stdscr)) != ERR) { if (_charprocfunc != NULL) (* (void (*) (int)) _charprocfunc) (newchar); } gettimeofday(&now,NULL); // Are we due for an update? if ((now.tv_sec < due.tv_sec) || ((now.tv_sec == due.tv_sec) && (now.tv_usec * 1000 < due.tv_nsec))) { // OK, now sleep until the next update // or until some work wakes us up pthread_mutex_lock (&_updatelock); pthread_cond_timedwait(&_updatecond, &_updatelock, &due); pthread_mutex_unlock (&_updatelock); } #ifdef DEBUG else { fprintf(dbglog, "Skipped pthread_cond_timedwait() Now %d:%09d Due %d:%09d\n", (int) now.tv_sec, (int) now.tv_usec * 1000, (int) due.tv_sec, (int) due.tv_nsec); } #endif } threadExit(); }
BOOST_FOREACH(const Thread & kt, killedThreads) {threadExit(kt.tid);}