void _st_vp_schedule(void) { st_thread_t *thread; while (_ST_RUNQ.next != &_ST_RUNQ) { /* Pull thread off of the run queue */ thread = _ST_THREAD_PTR(_ST_RUNQ.next); _ST_DEL_RUNQ(thread); ST_ASSERT(thread->state == _ST_ST_RUNNABLE); /* Resume the thread */ thread->state = _ST_ST_RUNNING; _ST_RESTORE_CONTEXT(thread); } { /* If there are no threads to run, switch to the idle thread */ thread = _st_this_vp.idle_thread; ST_ASSERT(thread->state == _ST_ST_RUNNABLE); thread->state = _ST_ST_RUNNING; _ST_RESTORE_CONTEXT(thread); /* Resume the thread */ } }
/* ARGSUSED */ void *_st_idle_thread_start(void *arg) { _st_thread_t *me = _ST_CURRENT_THREAD(); while (_st_active_count > 0) { /* Idle vp till I/O is ready or the smallest timeout expired */ _ST_VP_IDLE(); /* Check sleep queue for expired threads */ _st_vp_check_clock(); me->state = _ST_ST_RUNNABLE; _ST_SWITCH_CONTEXT(me); } _ST_RESTORE_CONTEXT(_st_this_vp.primorial_thread); /* No more threads */ free(_st_this_vp.primorial_thread); /* Free resources in use by event system */ (*_st_eventsys->free)(); return NULL; }