[PATCH 1/2] callout(9): introduce callout_reset_{,m}s, similarly to timeout_add_{,m}sec on OpenBSD

Constantine A. Murenin cnst+dfly at bugmail.mojo.ru
Wed Feb 24 15:23:50 PST 2010


---
 sys/kern/kern_timeout.c |   26 ++++++++++++++++++++++++++
 sys/sys/callout.h       |    2 ++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index 189ffb0..c296c1c 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -109,6 +109,8 @@
 #include <sys/thread2.h>
 #include <sys/mplock2.h>
 
+#include <machine/limits.h>
+
 #ifndef MAX_SOFTCLOCK_STEPS
 #define MAX_SOFTCLOCK_STEPS 100 /* Maximum allowed value of steps. */
 #endif
@@ -385,6 +387,30 @@ callout_reset(struct callout *c, int to_ticks, void (*ftn)(void *),
 	crit_exit_gd(gd);
 }
 
+void
+callout_reset_s(struct callout *c, int s, void (*ftn)(void *),
+    void *arg)
+{
+	uintmax_t t;
+
+	t = (uintmax_t)s * hz;
+	if (t > INT_MAX)
+		t = INT_MAX;
+	callout_reset(c, t, ftn, arg);
+}
+
+void
+callout_reset_ms(struct callout *c, int ms, void (*ftn)(void *),
+    void *arg)
+{
+	uintmax_t t;
+
+	t = (uintmax_t)ms * hz / 1000;
+	if (t > INT_MAX)
+		t = INT_MAX;
+	callout_reset(c, t, ftn, arg);
+}
+
 /*
  * Stop a running timer.  WARNING!  If called on a cpu other then the one
  * the callout was started on this function will liveloop on its IPI to
diff --git a/sys/sys/callout.h b/sys/sys/callout.h
index 5113793..492c01e 100644
--- a/sys/sys/callout.h
+++ b/sys/sys/callout.h
@@ -92,6 +92,8 @@ void	hardclock_softtick(struct globaldata *);
 void	callout_init (struct callout *);
 void	callout_init_mp (struct callout *);
 void	callout_reset (struct callout *, int, void (*)(void *), void *);
+void	callout_reset_s (struct callout *, int, void (*)(void *), void *);
+void	callout_reset_ms (struct callout *, int, void (*)(void *), void *);
 int	callout_stop (struct callout *);
 
 #endif
-- 
1.6.6


--M9NhX3UHpAaciwkO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline; filename="0002-callout.9-document-callout_reset_-m-s.patch"





More information about the Submit mailing list