《操作系统》的实验代码。
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.

52 lines
1.2 KiB

10 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);
  9. bool intr_flag;
  10. local_intr_save(intr_flag);
  11. {
  12. if (proc->state != PROC_RUNNABLE) {
  13. proc->state = PROC_RUNNABLE;
  14. proc->wait_state = 0;
  15. }
  16. else {
  17. warn("wakeup runnable process.\n");
  18. }
  19. }
  20. local_intr_restore(intr_flag);
  21. }
  22. void
  23. schedule(void) {
  24. bool intr_flag;
  25. list_entry_t *le, *last;
  26. struct proc_struct *next = NULL;
  27. local_intr_save(intr_flag);
  28. {
  29. current->need_resched = 0;
  30. last = (current == idleproc) ? &proc_list : &(current->list_link);
  31. le = last;
  32. do {
  33. if ((le = list_next(le)) != &proc_list) {
  34. next = le2proc(le, list_link);
  35. if (next->state == PROC_RUNNABLE) {
  36. break;
  37. }
  38. }
  39. } while (le != last);
  40. if (next == NULL || next->state != PROC_RUNNABLE) {
  41. next = idleproc;
  42. }
  43. next->runs ++;
  44. if (next != current) {
  45. proc_run(next);
  46. }
  47. }
  48. local_intr_restore(intr_flag);
  49. }