int minithread_system_cleanup(void) {
	multilevel_queue_free(ready_queue);
	queue_free(stop_queue);
	queue_free(dead_queue);
	minithread_free(idle);
	dbgprintf("minithread system cleaned up and shut down.\n");
	return 0;
}
예제 #2
0
static int clean_stopped_threads(int *arg) {
  while (1) {
    // disable interrupts in this section, so that interrupt handler
    // cannot disrupt the deletion of threads.
    interrupt_level_t old_level = set_interrupt_level(DISABLED);
    assert(stopped_queue);
    minithread_t *t = NULL;
    while (queue_length(stopped_queue)) {
      queue_dequeue(stopped_queue, (void **)(&t));
      assert(t);
      minithread_free(t);
    }
    stop_running_thread();
    set_interrupt_level(old_level);
  }
  return 0;
}
/*
 * Idle / System thread body
 */
int minithread_idle() {
	while ( multilevel_queue_length(ready_queue) || queue_length(stop_queue) 
		|| queue_length(dead_queue) || alarm_has_ready() ) {
		while ( alarm_has_ready() ) {
			alarm_fire_next();
		}
		while ( queue_length(dead_queue) ) {
			minithread_t kill_thread;
			queue_dequeue(dead_queue, &kill_thread);
			minithread_free(kill_thread);
		}
		if ( multilevel_queue_length(ready_queue) ) {
			minithread_schedule();
		}
	}
	
	return 0;
}