callout.h revision 173760
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 * 4. Neither the name of the University nor the names of its contributors
191541Srgrimes *    may be used to endorse or promote products derived from this software
201541Srgrimes *    without specific prior written permission.
211541Srgrimes *
221541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321541Srgrimes * SUCH DAMAGE.
331541Srgrimes *
341541Srgrimes *	@(#)callout.h	8.2 (Berkeley) 1/21/94
3550477Speter * $FreeBSD: head/sys/sys/callout.h 173760 2007-11-20 00:37:45Z attilio $
361541Srgrimes */
371541Srgrimes
382165Spaul#ifndef _SYS_CALLOUT_H_
392165Spaul#define _SYS_CALLOUT_H_
402165Spaul
4129683Sgibbs#include <sys/queue.h>
4229683Sgibbs
43173760Sattiliostruct lock_object;
44141428Siedowse
4560938SjakeSLIST_HEAD(callout_list, callout);
4660938SjakeTAILQ_HEAD(callout_tailq, callout);
4729683Sgibbs
4883045Sobrienstruct callout {
4929683Sgibbs	union {
5060938Sjake		SLIST_ENTRY(callout) sle;
5160938Sjake		TAILQ_ENTRY(callout) tqe;
5229683Sgibbs	} c_links;
5331470Sdg	int	c_time;				/* ticks to the event */
541541Srgrimes	void	*c_arg;				/* function argument */
5592719Salfred	void	(*c_func)(void *);	/* function to call */
56173760Sattilio	struct lock_object *c_lock;		/* lock to handle */
5744510Swollman	int	c_flags;			/* state of this entry */
581541Srgrimes};
591541Srgrimes
6044510Swollman#define	CALLOUT_LOCAL_ALLOC	0x0001 /* was allocated from callfree */
6150673Sjlemon#define	CALLOUT_ACTIVE		0x0002 /* callout is currently active */
6250673Sjlemon#define	CALLOUT_PENDING		0x0004 /* callout is waiting for timeout */
6368889Sjake#define	CALLOUT_MPSAFE		0x0008 /* callout handler is mp safe */
64141428Siedowse#define	CALLOUT_RETURNUNLOCKED	0x0010 /* handler returns with mtx unlocked */
65173760Sattilio#define	CALLOUT_SHAREDLOCK	0x0020 /* callout lock held in shared mode */
6644510Swollman
6783045Sobrienstruct callout_handle {
6829683Sgibbs	struct callout *callout;
6929683Sgibbs};
7029683Sgibbs
7155205Speter#ifdef _KERNEL
7229683Sgibbsextern struct callout_list callfree;
7329683Sgibbsextern struct callout *callout;
7482064Sjhbextern int ncallout;
7529683Sgibbsextern struct callout_tailq *callwheel;
7682064Sjhbextern int callwheelsize, callwheelbits, callwheelmask, softticks;
7768889Sjakeextern struct mtx callout_lock;
7844510Swollman
7950673Sjlemon#define	callout_active(c)	((c)->c_flags & CALLOUT_ACTIVE)
8050673Sjlemon#define	callout_deactivate(c)	((c)->c_flags &= ~CALLOUT_ACTIVE)
81128485Scperciva#define	callout_drain(c)	_callout_stop_safe(c, 1)
8292719Salfredvoid	callout_init(struct callout *, int);
83173760Sattiliovoid	_callout_init_lock(struct callout *, struct lock_object *, int);
84173760Sattilio#define	callout_init_mtx(c, mtx, flags)					\
85173760Sattilio	_callout_init_lock((c), ((mtx) != NULL) ? &(mtx)->lock_object :	\
86173760Sattilio	    NULL, (flags))
87173760Sattilio#define	callout_init_rw(c, rw, flags)					\
88173760Sattilio	_callout_init_lock((c), ((rw) != NULL) ? &(rw)->lock_object :	\
89173760Sattilio	   NULL, (flags))
9050673Sjlemon#define	callout_pending(c)	((c)->c_flags & CALLOUT_PENDING)
91149879Sglebiusint	callout_reset(struct callout *, int, void (*)(void *), void *);
92127969Scperciva#define	callout_stop(c)		_callout_stop_safe(c, 0)
93127969Scpercivaint	_callout_stop_safe(struct callout *, int);
9444510Swollman
9555205Speter#endif
962165Spaul
9729683Sgibbs#endif /* _SYS_CALLOUT_H_ */
98