diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2001-03-28 07:33:52 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2001-03-28 07:33:52 +0000 |
commit | 388195aa220dc727ff3ec503c2774079235c3ff1 (patch) | |
tree | 86a4dbffc4d984f77daa3054a6b4d28a956d1096 /sys/kern | |
parent | cfbae0773dbe897d6166048dbafceb4b02afdf9d (diff) |
Add some DIAGNOSTIC checks that panic on some of the common mistakes.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_timeout.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c index 04e74fd62c2..a314e2e77e6 100644 --- a/sys/kern/kern_timeout.c +++ b/sys/kern/kern_timeout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_timeout.c,v 1.7 2001/03/15 16:47:50 csapuntz Exp $ */ +/* $OpenBSD: kern_timeout.c,v 1.8 2001/03/28 07:33:51 art Exp $ */ /* * Copyright (c) 2000 Artur Grabowski <art@openbsd.org> * All rights reserved. @@ -92,15 +92,34 @@ timeout_init() } void -timeout_set(to, fn, arg) - struct timeout *to; +timeout_set(new, fn, arg) + struct timeout *new; void (*fn)(void *); void *arg; { - to->to_func = fn; - to->to_arg = arg; - to->to_flags = TIMEOUT_INITIALIZED; +#ifdef DIAGNOSTIC + struct timeout *to; + int s; + + /* + * Be careful. We could be called with random non-zero memory, but + * on the other hand we could be called with a timeout that's + * already queued. + * XXX - this is expensive. + */ + timeout_list_lock(&s); + if (new->to_flags & TIMEOUT_ONQUEUE) { + TAILQ_FOREACH(to, &timeout_todo, to_list) + if (to == new) + panic("timeout_set: on queue"); + } + timeout_list_unlock(s); +#endif + + new->to_func = fn; + new->to_arg = arg; + new->to_flags = TIMEOUT_INITIALIZED; } void @@ -116,6 +135,8 @@ timeout_add(new, to_ticks) */ #ifdef DIAGNOSTIC + if (!(new->to_flags & TIMEOUT_INITIALIZED)) + panic("timeout_add: not initialized"); if (to_ticks < 0) panic("timeout_add: to_ticks < 0"); #endif @@ -198,7 +219,10 @@ softclock() timeout_list_lock(&s); while ((to = TAILQ_FIRST(&timeout_todo)) != NULL && to->to_time - ticks <= 0) { - +#ifdef DIAGNOSTIC + if (!(to->to_flags & TIMEOUT_ONQUEUE)) + panic("softclock: not onqueue"); +#endif TAILQ_REMOVE(&timeout_todo, to, to_list); to->to_flags &= ~TIMEOUT_ONQUEUE; to->to_flags |= TIMEOUT_TRIGGERED; |