callout.h revision 44510
11541Srgrimes/*-
21541Srgrimes * Copyright (c) 1990, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes * (c) UNIX System Laboratories, Inc.
51541Srgrimes * All or some portions of this file are derived from material licensed
61541Srgrimes * to the University of California by American Telephone and Telegraph
71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81541Srgrimes * the permission of UNIX System Laboratories, Inc.
91541Srgrimes *
101541Srgrimes * Redistribution and use in source and binary forms, with or without
111541Srgrimes * modification, are permitted provided that the following conditions
121541Srgrimes * are met:
131541Srgrimes * 1. Redistributions of source code must retain the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer.
151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer in the
171541Srgrimes *    documentation and/or other materials provided with the distribution.
181541Srgrimes * 3. All advertising materials mentioning features or use of this software
191541Srgrimes *    must display the following acknowledgement:
201541Srgrimes *	This product includes software developed by the University of
211541Srgrimes *	California, Berkeley and its contributors.
221541Srgrimes * 4. Neither the name of the University nor the names of its contributors
231541Srgrimes *    may be used to endorse or promote products derived from this software
241541Srgrimes *    without specific prior written permission.
251541Srgrimes *
261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361541Srgrimes * SUCH DAMAGE.
371541Srgrimes *
381541Srgrimes *	@(#)callout.h	8.2 (Berkeley) 1/21/94
3944510Swollman * $Id: callout.h,v 1.11 1998/01/11 00:43:51 phk Exp $
401541Srgrimes */
411541Srgrimes
422165Spaul#ifndef _SYS_CALLOUT_H_
432165Spaul#define _SYS_CALLOUT_H_
442165Spaul
4529683Sgibbs#include <sys/queue.h>
4629683Sgibbs
4729683SgibbsSLIST_HEAD(callout_list, callout);
4829683SgibbsTAILQ_HEAD(callout_tailq, callout);
4929683Sgibbs
501541Srgrimesstruct callout {
5129683Sgibbs	union {
5229683Sgibbs		SLIST_ENTRY(callout) sle;
5329683Sgibbs		TAILQ_ENTRY(callout) tqe;
5429683Sgibbs	} c_links;
5531470Sdg	int	c_time;				/* ticks to the event */
561541Srgrimes	void	*c_arg;				/* function argument */
571541Srgrimes	void	(*c_func) __P((void *));	/* function to call */
5844510Swollman	int	c_flags;			/* state of this entry */
591541Srgrimes};
601541Srgrimes
6144510Swollman#define	CALLOUT_LOCAL_ALLOC	0x0001 /* was allocated from callfree */
6244510Swollman#define	CALLOUT_PENDING		0x0002 /* callout is currently active */
6344510Swollman#define	CALLOUT_FIRED		0x0004 /* callout has been fired */
6444510Swollman
6529683Sgibbsstruct callout_handle {
6629683Sgibbs	struct callout *callout;
6729683Sgibbs};
6829683Sgibbs
691541Srgrimes#ifdef KERNEL
7029683Sgibbsextern struct callout_list callfree;
7129683Sgibbsextern struct callout *callout;
722112Swollmanextern int	ncallout;
7329683Sgibbsextern struct callout_tailq *callwheel;
7432412Sphkextern int	callwheelsize, callwheelbits, callwheelmask, softticks;
7544510Swollman
7644510Swollman#define	callout_fired(c)	((c)->c_flags & CALLOUT_FIRED)
7744510Swollmanvoid	callout_init __P((struct callout *));
7844510Swollman#define	callout_pending(c)	(((c)->c_flags & CALLOUT_PENDING) ? \
7944510Swollman				 ((c)->c_time - ticks) : 0)
8044510Swollmanvoid	callout_reset __P((struct callout *, int, void (*)(void *), void *));
8144510Swollmanvoid	callout_stop __P((struct callout *));
8244510Swollman
8329683Sgibbs#endif /* KERNEL */
842165Spaul
8529683Sgibbs#endif /* _SYS_CALLOUT_H_ */
86