void *simplethread_threadproc(t_simplethread *x) { // loop until told to stop while (1) { // test if we're being asked to die, and if so return before we do the work if (x->x_systhread_cancel) break; systhread_mutex_lock(x->x_mutex); x->x_foo++; // fiddle with shared data systhread_mutex_unlock(x->x_mutex); qelem_set(x->x_qelem); // notify main thread using qelem mechanism systhread_sleep(x->x_sleeptime); // sleep a bit } x->x_systhread_cancel = false; // reset cancel flag for next time, in case // the thread is created again systhread_exit(0); // this can return a value to systhread_join(); return NULL; }
// // Send a to the poll workers (to make sure it is not blocked) // and clear the connections. // void PollManager::Terminate() { PRUint32 i; for (i = 0; i < numThreads_; i++) threads_[i]->RequestTermination(); for (i = 0; i < numThreads_; i++) { while (threads_[i]->isRunning()) systhread_sleep(10); } }
NSAPI_PUBLIC void fsmutex_lock(FSMUTEX id) { fsmutex_s *fsm = (fsmutex_s *) id; #ifdef THREAD_ANY if(fsm->flags & FSMUTEX_NEEDCRIT) crit_enter(fsm->crit); #endif #ifdef THREAD_NSPR_USER /* Poll to avoid blocking. XXXrobm If errno is wrong this may go awry. */ while(system_tlock(fsm->mutex) == -1) systhread_sleep(1000); #else system_flock(fsm->mutex ); #endif }
void WA_yield() { /* Couldn't find a 'yield' in NSAPI. A 1 ms sleep may be overkill. */ systhread_sleep(1); }