summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2013-10-06 04:34:35 +0000
committerguenther <guenther@openbsd.org>2013-10-06 04:34:35 +0000
commit760c8002c285af7d3d266cda747fbed8f3947b68 (patch)
tree0ba544eabc4d1b51011b058ca489c273040cb75e
parentAdd CLOCK_UPTIME, a clock which measures time-running-not-suspended, so (diff)
downloadwireguard-openbsd-760c8002c285af7d3d266cda747fbed8f3947b68.tar.xz
wireguard-openbsd-760c8002c285af7d3d266cda747fbed8f3947b68.zip
Replace some XXX casts with an inline function that explains what's going on
ok deraadt@
-rw-r--r--sys/kern/kern_timeout.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index bdf1177009d..2831fc3455e 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_timeout.c,v 1.39 2013/10/02 21:03:21 sf Exp $ */
+/* $OpenBSD: kern_timeout.c,v 1.40 2013/10/06 04:34:35 guenther Exp $ */
/*
* Copyright (c) 2001 Thomas Nordin <nordin@openbsd.org>
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
@@ -73,6 +73,17 @@ struct circq timeout_todo; /* Worklist */
&timeout_wheel[MASKWHEEL((wheel), (time)) + (wheel)*WHEELSIZE])
/*
+ * The first thing in a struct timeout is its struct circq, so we
+ * can get back from a pointer to the latter to a pointer to the
+ * whole timeout with just a cast.
+ */
+static __inline struct timeout *
+timeout_from_circq(struct circq *p)
+{
+ return ((struct timeout *)(p));
+}
+
+/*
* All wheels are locked with the same mutex.
*
* We need locking since the timeouts are manipulated from hardclock that's
@@ -317,7 +328,7 @@ softclock(void *arg)
mtx_enter(&timeout_mutex);
while (!CIRCQ_EMPTY(&timeout_todo)) {
- to = (struct timeout *)CIRCQ_FIRST(&timeout_todo); /* XXX */
+ to = timeout_from_circq(CIRCQ_FIRST(&timeout_todo));
CIRCQ_REMOVE(&to->to_list);
/* If due run it, otherwise insert it into the right bucket. */
@@ -361,7 +372,7 @@ timeout_adjust_ticks(int adj)
for (b = 0; b < nitems(timeout_wheel); b++) {
p = CIRCQ_FIRST(&timeout_wheel[b]);
while (p != &timeout_wheel[b]) {
- to = (struct timeout *)p; /* XXX */
+ to = timeout_from_circq(p);
p = CIRCQ_FIRST(p);
/* when moving a timeout forward need to reinsert it */
@@ -388,7 +399,7 @@ db_show_callout_bucket(struct circq *bucket)
char *name;
for (p = CIRCQ_FIRST(bucket); p != bucket; p = CIRCQ_FIRST(p)) {
- to = (struct timeout *)p; /* XXX */
+ to = timeout_from_circq(p);
db_find_sym_and_offset((db_addr_t)to->to_func, &name, &offset);
name = name ? name : "?";
db_printf("%9d %2td/%-4td %p %s\n", to->to_time - ticks,