mirror of
https://github.com/SmallPond/MIT6.828_OS.git
synced 2026-07-06 11:58:02 +08:00
my solution to lab 6
This commit is contained in:
32
lab/net/timer.c
Normal file
32
lab/net/timer.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "ns.h"
|
||||
|
||||
void
|
||||
timer(envid_t ns_envid, uint32_t initial_to) {
|
||||
int r;
|
||||
uint32_t stop = sys_time_msec() + initial_to;
|
||||
|
||||
binaryname = "ns_timer";
|
||||
|
||||
while (1) {
|
||||
while((r = sys_time_msec()) < stop && r >= 0) {
|
||||
sys_yield();
|
||||
}
|
||||
if (r < 0)
|
||||
panic("sys_time_msec: %e", r);
|
||||
|
||||
ipc_send(ns_envid, NSREQ_TIMER, 0, 0);
|
||||
|
||||
while (1) {
|
||||
uint32_t to, whom;
|
||||
to = ipc_recv((int32_t *) &whom, 0, 0);
|
||||
|
||||
if (whom != ns_envid) {
|
||||
cprintf("NS TIMER: timer thread got IPC message from env %x not NS\n", whom);
|
||||
continue;
|
||||
}
|
||||
|
||||
stop = sys_time_msec() + to;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user