[BACK]Return to timeout.h CVS log [TXT][DIR] Up to [local] / sys / sys

Annotation of sys/sys/timeout.h, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: timeout.h,v 1.16 2003/06/03 01:27:31 art Exp $        */
                      2: /*
                      3:  * Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. The name of the author may not be used to endorse or promote products
                     13:  *    derived from this software without specific prior written permission.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     16:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     17:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
                     18:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     19:  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     20:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     21:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     22:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     23:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     25:  */
                     26:
                     27: #ifndef _SYS_TIMEOUT_H_
                     28: #define _SYS_TIMEOUT_H_
                     29:
                     30: /*
                     31:  * Interface for handling time driven events in the kernel.
                     32:  *
                     33:  * The basic component of this API is the struct timeout. The user should not
                     34:  * touch the internals of this structure, but it's the users responsibility
                     35:  * to allocate and deallocate timeouts.
                     36:  *
                     37:  * The functions used to manipulate timeouts are:
                     38:  *  - timeout_set(timeout, function, argument)
                     39:  *      Initializes a timeout struct to call the function with the argument.
                     40:  *      A timeout only needs to be initialized once.
                     41:  *  - timeout_add(timeout, ticks)
                     42:  *      Schedule this timeout to run in "ticks" ticks (there are hz ticks in
                     43:  *      one second). You may not touch the timeout with timeout_set once the
                     44:  *      timeout is scheduled. A second call to timeout_add with an already
                     45:  *      scheduled timeout will cause the old timeout to be canceled and the
                     46:  *      new will be scheduled.
                     47:  *  - timeout_del(timeout)
                     48:  *      Remove the timeout from the timeout queue. It's legal to remove
                     49:  *      a timeout that has already happened.
                     50:  *
                     51:  * These functions may be called in interrupt context (anything below splhigh).
                     52:  */
                     53:
                     54: struct circq {
                     55:        struct circq *next;             /* next element */
                     56:        struct circq *prev;             /* previous element */
                     57: };
                     58:
                     59: struct timeout {
                     60:        struct circq to_list;                   /* timeout queue, don't move */
                     61:        void (*to_func)(void *);                /* function to call */
                     62:        void *to_arg;                           /* function argument */
                     63:        int to_time;                            /* ticks on event */
                     64:        int to_flags;                           /* misc flags */
                     65: };
                     66:
                     67: /*
                     68:  * flags in the to_flags field.
                     69:  */
                     70: #define TIMEOUT_ONQUEUE                2       /* timeout is on the todo queue */
                     71: #define TIMEOUT_INITIALIZED    4       /* timeout is initialized */
                     72: #define TIMEOUT_TRIGGERED       8       /* timeout is running or ran */
                     73: /*
                     74:  * special macros
                     75:  *
                     76:  * timeout_pending(to) - is this timeout already scheduled to run?
                     77:  * timeout_initialized(to) - is this timeout initialized?
                     78:  */
                     79: #define timeout_pending(to) ((to)->to_flags & TIMEOUT_ONQUEUE)
                     80: #define timeout_initialized(to) ((to)->to_flags & TIMEOUT_INITIALIZED)
                     81: #define timeout_triggered(to) ((to)->to_flags & TIMEOUT_TRIGGERED)
                     82:
                     83: #ifdef _KERNEL
                     84: void timeout_set(struct timeout *, void (*)(void *), void *);
                     85: void timeout_add(struct timeout *, int);
                     86: void timeout_del(struct timeout *);
                     87:
                     88: void timeout_startup(void);
                     89:
                     90: /*
                     91:  * called once every hardclock. returns non-zero if we need to schedule a
                     92:  * softclock.
                     93:  */
                     94: int timeout_hardclock_update(void);
                     95: #endif /* _KERNEL */
                     96:
                     97: #endif /* _SYS_TIMEOUT_H_ */

CVSweb