《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1012 B

12 years ago
  1. #include <list.h>
  2. #include <sync.h>
  3. #include <proc.h>
  4. #include <sched.h>
  5. #include <assert.h>
  6. void
  7. wakeup_proc(struct proc_struct *proc) {
  8. assert(proc->state != PROC_ZOMBIE && proc->state != PROC_RUNNABLE);
  9. proc->state = PROC_RUNNABLE;
  10. }
  11. void
  12. schedule(void) {
  13. bool intr_flag;
  14. list_entry_t *le, *last;
  15. struct proc_struct *next = NULL;
  16. local_intr_save(intr_flag);
  17. {
  18. current->need_resched = 0;
  19. last = (current == idleproc) ? &proc_list : &(current->list_link);
  20. le = last;
  21. do {
  22. if ((le = list_next(le)) != &proc_list) {
  23. next = le2proc(le, list_link);
  24. if (next->state == PROC_RUNNABLE) {
  25. break;
  26. }
  27. }
  28. } while (le != last);
  29. if (next == NULL || next->state != PROC_RUNNABLE) {
  30. next = idleproc;
  31. }
  32. next->runs ++;
  33. if (next != current) {
  34. proc_run(next);
  35. }
  36. }
  37. local_intr_restore(intr_flag);
  38. }