From: dlg Date: Mon, 22 Dec 2014 04:43:38 +0000 (+0000) Subject: add TIMEOUT_INITIALIZER for initting timeout declaractions. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2c4d06f2e14b186285593780265a8236f9b9583a;p=openbsd add TIMEOUT_INITIALIZER for initting timeout declaractions. similar to TASK_INITIALIZER and all the queue _INITIALIZER things. ok deraadt@ --- diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index 44f0fd4893b..558cea2684a 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.225 2014/12/11 14:29:42 jmc Exp $ +# $OpenBSD: Makefile,v 1.226 2014/12/22 04:43:38 dlg Exp $ # $NetBSD: Makefile,v 1.4 1996/01/09 03:23:01 thorpej Exp $ # Makefile for section 9 (kernel function and variable) manual pages. @@ -385,7 +385,8 @@ MLINKS+=timeout.9 timeout_add.9 timeout.9 timeout_set.9 \ 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 wakeup_n.9 tsleep.9 wakeup_one.9 \ tsleep.9 msleep.9 MLINKS+=tvtohz.9 tstohz.9 diff --git a/share/man/man9/timeout.9 b/share/man/man9/timeout.9 index b0c8aef7de4..9034622336f 100644 --- a/share/man/man9/timeout.9 +++ b/share/man/man9/timeout.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: timeout.9,v 1.37 2014/02/13 14:20:07 jmc Exp $ +.\" $OpenBSD: timeout.9,v 1.38 2014/12/22 04:43:38 dlg Exp $ .\" .\" Copyright (c) 2000 Artur Grabowski .\" All rights reserved. @@ -23,7 +23,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: February 13 2014 $ +.Dd $Mdocdate: December 22 2014 $ .Dt TIMEOUT 9 .Os .Sh NAME @@ -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 @@ -173,6 +175,16 @@ 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 the +.Fa void * +argument given in +.Fa arg . .Sh CONTEXT .Fn timeout_set can be called during autoconf, from process context, or from interrupt diff --git a/sys/sys/timeout.h b/sys/sys/timeout.h index ddb7624c1c6..8f25af17e81 100644 --- a/sys/sys/timeout.h +++ b/sys/sys/timeout.h @@ -1,4 +1,4 @@ -/* $OpenBSD: timeout.h,v 1.24 2013/11/27 04:28:32 dlg Exp $ */ +/* $OpenBSD: timeout.h,v 1.25 2014/12/22 04:43:38 dlg Exp $ */ /* * Copyright (c) 2000-2001 Artur Grabowski * All rights reserved. @@ -82,6 +82,9 @@ struct timeout { #define timeout_initialized(to) ((to)->to_flags & TIMEOUT_INITIALIZED) #define timeout_triggered(to) ((to)->to_flags & TIMEOUT_TRIGGERED) +#define TIMEOUT_INITIALIZER(_f, _a) \ + { { NULL, NULL }, (_f), (_a), 0, TIMEOUT_INITIALIZED } + struct bintime; void timeout_set(struct timeout *, void (*)(void *), void *);