gonzui


Format: Advanced Search

t2ex/bsd_source/lib/libc/src_bsd/include/sys/timeout.hbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*      $OpenBSD: timeout.h,v 1.21 2011/05/10 00:58:42 dlg 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: #ifdef _KERNEL
   75: /*
   76:  * special macros
   77:  *
   78:  * timeout_pending(to) - is this timeout already scheduled to run?
   79:  * timeout_initialized(to) - is this timeout initialized?
   80:  */
   81: #define timeout_pending(to) ((to)->to_flags & TIMEOUT_ONQUEUE)
   82: #define timeout_initialized(to) ((to)->to_flags & TIMEOUT_INITIALIZED)
   83: #define timeout_triggered(to) ((to)->to_flags & TIMEOUT_TRIGGERED)
   84: 
   85: void timeout_set(struct timeout *, void (*)(void *), void *);
   86: void timeout_add(struct timeout *, int);
   87: void timeout_add_tv(struct timeout *, const struct timeval *);
   88: void timeout_add_ts(struct timeout *, const struct timespec *);
   89: void timeout_add_bt(struct timeout *, const struct bintime *);
   90: void timeout_add_sec(struct timeout *, int);
   91: void timeout_add_msec(struct timeout *, int);
   92: void timeout_add_usec(struct timeout *, int);
   93: void timeout_add_nsec(struct timeout *, int);
   94: int timeout_del(struct timeout *);
   95: 
   96: void timeout_startup(void);
   97: 
   98: /*
   99:  * called once every hardclock. returns non-zero if we need to schedule a
  100:  * softclock.
  101:  */
  102: int timeout_hardclock_update(void);
  103: #endif /* _KERNEL */
  104: 
  105: #endif  /* _SYS_TIMEOUT_H_ */