From 462d625c0dac39788a93e6d4563c1bf3ca65f874 Mon Sep 17 00:00:00 2001 From: David Gwynne Date: Thu, 10 Nov 2005 08:32:57 +0000 Subject: the tasklist can be modified while the kthread is sleeping, so refetch the first element before iterating through the rest of them. stylistic guidance from angela pascoe. mark all tasks using the same argument as not running anymore, rather than just the first one we bump into. --- sys/kern/kern_sensors.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_sensors.c b/sys/kern/kern_sensors.c index b8c0bd85304..83cc25b823b 100644 --- a/sys/kern/kern_sensors.c +++ b/sys/kern/kern_sensors.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sensors.c,v 1.2 2005/11/10 08:20:20 dlg Exp $ */ +/* $OpenBSD: kern_sensors.c,v 1.3 2005/11/10 08:32:56 dlg Exp $ */ /* * Copyright (c) 2005 David Gwynne @@ -65,6 +65,7 @@ sensor_task_register(void *arg, void (*func)(void *), int period) kthread_create_deferred(sensor_task_create, NULL); sensor_task_schedule(st); + wakeup(&tasklist); return (0); } @@ -78,10 +79,8 @@ sensor_task_unregister(void *arg) while ((st = nst) != NULL) { nst = TAILQ_NEXT(st, entry); - if (st->arg == arg) { + if (st->arg == arg) st->running = 0; - return; - } } } @@ -101,7 +100,8 @@ sensor_task_thread(void *arg) while (!TAILQ_EMPTY(&tasklist)) { nst = TAILQ_FIRST(&tasklist); - while (nst->nextrun > (now = time_uptime)) + while ((nst = TAILQ_FIRST(&tasklist))->nextrun > + (now = time_uptime)) tsleep(&tasklist, PWAIT, "timeout", (nst->nextrun - now) * hz); -- cgit v1.2.3