Binary files kozos04/koz and kozos05/koz differ Binary files kozos04/syscall.o and kozos05/syscall.o differ diff -ruN -U 10 kozos04/thread.c kozos05/thread.c --- kozos04/thread.c Mon Oct 22 00:45:58 2007 +++ kozos05/thread.c Mon Oct 22 00:45:58 2007 @@ -1,16 +1,17 @@ #include #include #include #include #include #include +#include #include "kozos.h" #include "syscall.h" #include "thread.h" #define SIG_NUM 32 #define STACK_SIZE 0x8000 typedef struct _kz_timebuf { struct _kz_timebuf *next; @@ -212,57 +213,74 @@ if (current->messages == NULL) { /* メッセージが無いのでブロックする */ return -1; } recvmsg(); putcurrent(); return current->syscall.param->un.recv.ret; } +static struct timeval alarm_tm; + static int thread_timer(int msec) { kz_timebuf **tmpp; kz_timebuf *tmp; + struct timeval tm; + int diffmsec; tmp = malloc(sizeof(*tmp)); tmp->next = NULL; tmp->thp = current; + gettimeofday(&tm, NULL); + if (timers) { + diffmsec = (tm.tv_sec - alarm_tm.tv_sec) * 1000 + + (tm.tv_usec - alarm_tm.tv_usec) / 1000; + if (timers->msec > diffmsec) + timers->msec -= diffmsec; + else + timers->msec = 0; + } + for (tmpp = &timers; *tmpp; tmpp = &((*tmpp)->next)) { if (msec < (*tmpp)->msec) { (*tmpp)->msec -= msec; break; } msec -= (*tmpp)->msec; } if (msec == 0) msec++; tmp->msec = msec; tmp->next = *tmpp; *tmpp = tmp; - ualarm(timers->msec * 1000, 0); + alarm_tm = tm; + if (tmpp == &timers) + ualarm(timers->msec * 1000, 0); putcurrent(); return 0; } void alarm_handler() { kz_timebuf *tmp; sendmsg(timers->thp, 0, 0, NULL); tmp = timers; timers = timers->next; free(tmp); if (timers) { + gettimeofday(&alarm_tm, NULL); ualarm(timers->msec * 1000, 0); } } static void syscall_proc() { /* システムコールの実行中にcurrentが書き換わるのでポインタを保存しておく */ kz_syscall_param_t *p = current->syscall.param; getcurrent(); Binary files kozos04/thread.o and kozos05/thread.o differ