diff --git a/arch/amd64/hw/timer.c b/arch/amd64/hw/timer.c index c1cfe82..ee45a97 100644 --- a/arch/amd64/hw/timer.c +++ b/arch/amd64/hw/timer.c @@ -41,20 +41,19 @@ void timer_add_sleep(struct thread *thr) { void timer_remove_sleep(struct thread *thr) { //if (thr->pid > 0) - //kdebug("Removing sleep %d\n", thr->pid); uintptr_t irq; - struct io_notify *n = &thr->sleep_notify; - struct io_notify *it; + //struct io_notify *n = &thr->sleep_notify; + //struct io_notify *it; spin_lock_irqsave(&g_sleep_lock, &irq); - list_for_each_entry(it, &g_sleep_head, link) { - if (it == n) { - list_del_init(&it->link); - spin_release_irqrestore(&g_sleep_lock, &irq); - return; - } - } + //list_for_each_entry(it, &g_sleep_head, link) { + // if (it == n) { + // list_del_init(&it->link); + // spin_release_irqrestore(&g_sleep_lock, &irq); + // return; + // } + //} + list_del_init(&thr->sleep_notify.link); spin_release_irqrestore(&g_sleep_lock, &irq); - panic("No such thread\n"); } static uint32_t timer_tick(void *arg) { @@ -90,6 +89,7 @@ static uint32_t timer_tick(void *arg) { struct thread *t = n->owner; if (!t) { + kdebug("Cleaning up ownerless sleep\n"); list_del_init(iter); continue; } diff --git a/sys/thread.c b/sys/thread.c index d4bb19b..c765d3d 100644 --- a/sys/thread.c +++ b/sys/thread.c @@ -609,8 +609,6 @@ void process_signal(struct process *proc, int signum) { if (thr->sleep_notify.owner) { thread_notify_io(&thr->sleep_notify); - //thr->sleep_notify.owner = NULL; - //timer_remove_sleep(thr); } if (thr->cpu == (int) get_cpu()->processor_id) { diff --git a/sys/wait.c b/sys/wait.c index bc4a255..3f50466 100644 --- a/sys/wait.c +++ b/sys/wait.c @@ -123,13 +123,13 @@ void thread_wait_io_clear(struct thread *t) { } int thread_sleep(struct thread *thr, uint64_t deadline, uint64_t *int_time) { + // Cancel previous sleep + list_del_init(&thr->sleep_notify.link); + thr->sleep_notify.value = 0; + thr->sleep_deadline = deadline; timer_add_sleep(thr); return thread_wait_io(thr, &thr->sleep_notify); - //// Store time when interrupt occured - //if (int_time) { - // *int_time = system_time; - //} } static int wait_check_pid(struct process *chld, int flags) {