1 #include <inc/assert.h>
5 #include <kern/monitor.h>
8 // Choose a user environment to run and run it.
12 // Implement simple round-robin scheduling.
13 // Search through 'envs' for a runnable environment,
14 // in circular fashion starting after the previously running env,
15 // and switch to the first such environment found.
16 // It's OK to choose the previously running env if no other env
18 // But never choose envs[0], the idle environment,
19 // unless NOTHING else is runnable.
20 // LAB 4: Your code here.
23 // if there are no previous running environment,
24 // set this to the envs, i.e. envs[0]
28 for (i
= curenv
- envs
+ 1; i
< NENV
; i
++)
29 if (envs
[i
].env_status
== ENV_RUNNABLE
)
32 for (i
= 1; i
<= curenv
- envs
; i
++)
33 if (envs
[i
].env_status
== ENV_RUNNABLE
)
36 // Run the special idle environment when nothing else is runnable.
37 if (envs
[0].env_status
== ENV_RUNNABLE
)
40 cprintf("Destroyed all environments - nothing more to do!\n");