add lab answers
This commit is contained in:
52
labcodes_answer/lab5_result/kern/schedule/sched.c
Normal file
52
labcodes_answer/lab5_result/kern/schedule/sched.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <list.h>
|
||||
#include <sync.h>
|
||||
#include <proc.h>
|
||||
#include <sched.h>
|
||||
#include <assert.h>
|
||||
|
||||
void
|
||||
wakeup_proc(struct proc_struct *proc) {
|
||||
assert(proc->state != PROC_ZOMBIE);
|
||||
bool intr_flag;
|
||||
local_intr_save(intr_flag);
|
||||
{
|
||||
if (proc->state != PROC_RUNNABLE) {
|
||||
proc->state = PROC_RUNNABLE;
|
||||
proc->wait_state = 0;
|
||||
}
|
||||
else {
|
||||
warn("wakeup runnable process.\n");
|
||||
}
|
||||
}
|
||||
local_intr_restore(intr_flag);
|
||||
}
|
||||
|
||||
void
|
||||
schedule(void) {
|
||||
bool intr_flag;
|
||||
list_entry_t *le, *last;
|
||||
struct proc_struct *next = NULL;
|
||||
local_intr_save(intr_flag);
|
||||
{
|
||||
current->need_resched = 0;
|
||||
last = (current == idleproc) ? &proc_list : &(current->list_link);
|
||||
le = last;
|
||||
do {
|
||||
if ((le = list_next(le)) != &proc_list) {
|
||||
next = le2proc(le, list_link);
|
||||
if (next->state == PROC_RUNNABLE) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (le != last);
|
||||
if (next == NULL || next->state != PROC_RUNNABLE) {
|
||||
next = idleproc;
|
||||
}
|
||||
next->runs ++;
|
||||
if (next != current) {
|
||||
proc_run(next);
|
||||
}
|
||||
}
|
||||
local_intr_restore(intr_flag);
|
||||
}
|
||||
|
||||
10
labcodes_answer/lab5_result/kern/schedule/sched.h
Normal file
10
labcodes_answer/lab5_result/kern/schedule/sched.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __KERN_SCHEDULE_SCHED_H__
|
||||
#define __KERN_SCHEDULE_SCHED_H__
|
||||
|
||||
#include <proc.h>
|
||||
|
||||
void schedule(void);
|
||||
void wakeup_proc(struct proc_struct *proc);
|
||||
|
||||
#endif /* !__KERN_SCHEDULE_SCHED_H__ */
|
||||
|
||||
Reference in New Issue
Block a user