mirror of
https://github.com/SmallPond/MIT6.828_OS.git
synced 2026-02-03 02:53:21 +08:00
36 lines
563 B
C
36 lines
563 B
C
#include <inc/lib.h>
|
|
#include <inc/x86.h>
|
|
|
|
void
|
|
sleep(int sec)
|
|
{
|
|
unsigned now = sys_time_msec();
|
|
unsigned end = now + sec * 1000;
|
|
|
|
if ((int)now < 0 && (int)now > -MAXERROR)
|
|
panic("sys_time_msec: %e", (int)now);
|
|
if (end < now)
|
|
panic("sleep: wrap");
|
|
|
|
while (sys_time_msec() < end)
|
|
sys_yield();
|
|
}
|
|
|
|
void
|
|
umain(int argc, char **argv)
|
|
{
|
|
int i;
|
|
|
|
// Wait for the console to calm down
|
|
for (i = 0; i < 50; i++)
|
|
sys_yield();
|
|
|
|
cprintf("starting count down: ");
|
|
for (i = 5; i >= 0; i--) {
|
|
cprintf("%d ", i);
|
|
sleep(1);
|
|
}
|
|
cprintf("\n");
|
|
breakpoint();
|
|
}
|