this lets you init a timeout when its declared, much like how things
like MUTEX_INITIALIZER or RWLOCK_INITIALIZER work.

ok?

Index: sys/sys/timeout.h
===================================================================
RCS file: /cvs/src/sys/sys/timeout.h,v
retrieving revision 1.24
diff -u -p -r1.24 timeout.h
--- sys/sys/timeout.h   27 Nov 2013 04:28:32 -0000      1.24
+++ sys/sys/timeout.h   9 Dec 2013 03:51:22 -0000
@@ -64,6 +64,9 @@ struct timeout {
        int to_flags;                           /* misc flags */
 };
 
+#define TIMEOUT_INITIALIZER(_f, _a) \
+       { { NULL, NULL }, (_f), (_a), 0, TIMEOUT_INITIALIZED }
+
 /*
  * flags in the to_flags field.
  */
Index: share/man/man9/timeout.9
===================================================================
RCS file: /cvs/src/share/man/man9/timeout.9,v
retrieving revision 1.33
diff -u -p -r1.33 timeout.9
--- share/man/man9/timeout.9    27 Nov 2013 04:28:32 -0000      1.33
+++ share/man/man9/timeout.9    9 Dec 2013 03:51:22 -0000
@@ -39,7 +39,8 @@
 .Nm timeout_del ,
 .Nm timeout_pending ,
 .Nm timeout_initialized ,
-.Nm timeout_triggered
+.Nm timeout_triggered ,
+.Nm TIMEOUT_INITIALIZER
 .Nd execute a function after a specified period of time
 .Sh SYNOPSIS
 .In sys/types.h
@@ -70,6 +71,7 @@
 .Fn "timeout_add_usec" "struct timeout *to" "int usec"
 .Ft int
 .Fn "timeout_add_nsec" "struct timeout *to" "int nsec"
+.Fn "TIMEOUT_INITIALIZER" "void (*fn)(void *)" "void *arg"
 .Sh DESCRIPTION
 The
 .Nm timeout
@@ -181,6 +183,17 @@ functions instead of
 .Fn timeout_add .
 Those functions add a timeout whilst converting the time specified
 by the respective types.
+.Pp
+A timeout declaration can be initialised with the
+.Fn TIMEOUT_INITIALIZER
+macro.
+The timeout will be prepared to call the function specified by the
+.Fa fn
+argument with a
+.Fa void *
+argument given in the
+.Fa arg
+argument.
 .Sh CODE REFERENCES
 These functions are implemented in the file
 .Pa sys/kern/kern_timeout.c .
Index: share/man/man9/Makefile
===================================================================
RCS file: /cvs/src/share/man/man9/Makefile,v
retrieving revision 1.190
diff -u -p -r1.190 Makefile
--- share/man/man9/Makefile     9 Dec 2013 03:14:30 -0000       1.190
+++ share/man/man9/Makefile     9 Dec 2013 03:51:22 -0000
@@ -337,7 +337,8 @@ MLINKS+=timeout.9 timeout_add.9 timeout.
        timeout.9 timeout_add_sec.9 \
        timeout.9 timeout_add_msec.9 \
        timeout.9 timeout_add_usec.9 \
-       timeout.9 timeout_add_nsec.9
+       timeout.9 timeout_add_nsec.9 \
+       timeout.9 TIMEOUT_INITIALIZER.9 
 MLINKS+=tsleep.9 wakeup.9 tsleep.9 msleep.9
 MLINKS+=tvtohz.9 tstohz.9
 MLINKS+=uiomove.9 uio.9

Reply via email to