xref: /dflybsd-src/sys/netinet/tcp_timer2.h (revision eb67213abec698ffb555ee926f2761bcb7e95f55)
1a48c5dd5SSepherosa Ziehau /*
2a48c5dd5SSepherosa Ziehau  * Copyright (c) 1982, 1986, 1993
3a48c5dd5SSepherosa Ziehau  *	The Regents of the University of California.  All rights reserved.
4a48c5dd5SSepherosa Ziehau  *
5a48c5dd5SSepherosa Ziehau  * Redistribution and use in source and binary forms, with or without
6a48c5dd5SSepherosa Ziehau  * modification, are permitted provided that the following conditions
7a48c5dd5SSepherosa Ziehau  * are met:
8a48c5dd5SSepherosa Ziehau  * 1. Redistributions of source code must retain the above copyright
9a48c5dd5SSepherosa Ziehau  *    notice, this list of conditions and the following disclaimer.
10a48c5dd5SSepherosa Ziehau  * 2. Redistributions in binary form must reproduce the above copyright
11a48c5dd5SSepherosa Ziehau  *    notice, this list of conditions and the following disclaimer in the
12a48c5dd5SSepherosa Ziehau  *    documentation and/or other materials provided with the distribution.
132c64e990Szrj  * 3. Neither the name of the University nor the names of its contributors
14a48c5dd5SSepherosa Ziehau  *    may be used to endorse or promote products derived from this software
15a48c5dd5SSepherosa Ziehau  *    without specific prior written permission.
16a48c5dd5SSepherosa Ziehau  *
17a48c5dd5SSepherosa Ziehau  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18a48c5dd5SSepherosa Ziehau  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19a48c5dd5SSepherosa Ziehau  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20a48c5dd5SSepherosa Ziehau  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21a48c5dd5SSepherosa Ziehau  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22a48c5dd5SSepherosa Ziehau  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23a48c5dd5SSepherosa Ziehau  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24a48c5dd5SSepherosa Ziehau  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25a48c5dd5SSepherosa Ziehau  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26a48c5dd5SSepherosa Ziehau  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a48c5dd5SSepherosa Ziehau  * SUCH DAMAGE.
28a48c5dd5SSepherosa Ziehau  *
29a48c5dd5SSepherosa Ziehau  *	@(#)tcp_timer.h	8.1 (Berkeley) 6/10/93
30a48c5dd5SSepherosa Ziehau  * $FreeBSD: src/sys/netinet/tcp_timer.h,v 1.18.2.1 2002/08/16 22:16:39 dillon Exp $
31a48c5dd5SSepherosa Ziehau  * $DragonFly: src/sys/netinet/tcp_timer.h,v 1.3 2003/08/23 11:18:00 rob Exp $
32a48c5dd5SSepherosa Ziehau  */
33a48c5dd5SSepherosa Ziehau 
34a48c5dd5SSepherosa Ziehau #ifndef _NETINET_TCP_TIMER2_H_
35a48c5dd5SSepherosa Ziehau #define _NETINET_TCP_TIMER2_H_
36a48c5dd5SSepherosa Ziehau 
37a48c5dd5SSepherosa Ziehau #ifdef _KERNEL
38a48c5dd5SSepherosa Ziehau 
39e6f59cdaSSepherosa Ziehau #ifndef _SYS_PARAM_H_
40e6f59cdaSSepherosa Ziehau #include <sys/param.h>
41e6f59cdaSSepherosa Ziehau #endif
42e6f59cdaSSepherosa Ziehau 
43e6f59cdaSSepherosa Ziehau #ifndef _SYS_SYSTM_H_
44e6f59cdaSSepherosa Ziehau #include <sys/systm.h>
45e6f59cdaSSepherosa Ziehau #endif
46e6f59cdaSSepherosa Ziehau 
47a48c5dd5SSepherosa Ziehau #ifndef _SYS_THREAD2_H_
48a48c5dd5SSepherosa Ziehau #include <sys/thread2.h>
49a48c5dd5SSepherosa Ziehau #endif
50a48c5dd5SSepherosa Ziehau 
51a48c5dd5SSepherosa Ziehau #ifndef _SYS_CALLOUT_H_
52a48c5dd5SSepherosa Ziehau #include <sys/callout.h>
53a48c5dd5SSepherosa Ziehau #endif
54a48c5dd5SSepherosa Ziehau 
55a48c5dd5SSepherosa Ziehau #ifndef _NETINET_TCP_VAR_H_
56a48c5dd5SSepherosa Ziehau #include <netinet/tcp_var.h>
57a48c5dd5SSepherosa Ziehau #endif
58a48c5dd5SSepherosa Ziehau 
59a48c5dd5SSepherosa Ziehau #ifndef _NETINET_TCP_TIMER_H_
60a48c5dd5SSepherosa Ziehau #include <netinet/tcp_timer.h>
61a48c5dd5SSepherosa Ziehau #endif
62a48c5dd5SSepherosa Ziehau 
63a48c5dd5SSepherosa Ziehau static __inline void
tcp_callout_stop(struct tcpcb * _tp,struct tcp_callout * _tc)64a48c5dd5SSepherosa Ziehau tcp_callout_stop(struct tcpcb *_tp, struct tcp_callout *_tc)
65a48c5dd5SSepherosa Ziehau {
66e6f59cdaSSepherosa Ziehau 	KKASSERT(_tp->tt_msg->tt_cpuid == mycpuid);
67e6f59cdaSSepherosa Ziehau 
68a48c5dd5SSepherosa Ziehau 	crit_enter();
69a48c5dd5SSepherosa Ziehau 	callout_stop(&_tc->tc_callout);
70a48c5dd5SSepherosa Ziehau 	_tp->tt_msg->tt_tasks &= ~_tc->tc_task;
71a48c5dd5SSepherosa Ziehau 	_tp->tt_msg->tt_running_tasks &= ~_tc->tc_task;
72a48c5dd5SSepherosa Ziehau 	crit_exit();
73a48c5dd5SSepherosa Ziehau }
74a48c5dd5SSepherosa Ziehau 
75a48c5dd5SSepherosa Ziehau static __inline void
tcp_callout_terminate(struct tcpcb * _tp,struct tcp_callout * _tc)76*eb67213aSMatthew Dillon tcp_callout_terminate(struct tcpcb *_tp, struct tcp_callout *_tc)
77*eb67213aSMatthew Dillon {
78*eb67213aSMatthew Dillon 	KKASSERT(_tp->tt_msg->tt_cpuid == mycpuid);
79*eb67213aSMatthew Dillon 
80*eb67213aSMatthew Dillon 	crit_enter();
81*eb67213aSMatthew Dillon 	callout_terminate(&_tc->tc_callout);
82*eb67213aSMatthew Dillon 	_tp->tt_msg->tt_tasks &= ~_tc->tc_task;
83*eb67213aSMatthew Dillon 	_tp->tt_msg->tt_running_tasks &= ~_tc->tc_task;
84*eb67213aSMatthew Dillon 	crit_exit();
85*eb67213aSMatthew Dillon }
86*eb67213aSMatthew Dillon 
87*eb67213aSMatthew Dillon static __inline void
tcp_callout_reset(struct tcpcb * _tp,struct tcp_callout * _tc,int _to_ticks,void (* _func)(void *))88a48c5dd5SSepherosa Ziehau tcp_callout_reset(struct tcpcb *_tp, struct tcp_callout *_tc, int _to_ticks,
89a48c5dd5SSepherosa Ziehau 		  void (*_func)(void *))
90a48c5dd5SSepherosa Ziehau {
91e6f59cdaSSepherosa Ziehau 	KKASSERT(_tp->tt_msg->tt_cpuid == mycpuid);
92e6f59cdaSSepherosa Ziehau 
93a48c5dd5SSepherosa Ziehau 	crit_enter();
94a48c5dd5SSepherosa Ziehau 	callout_reset(&_tc->tc_callout, _to_ticks, _func, _tp);
95a48c5dd5SSepherosa Ziehau 	_tp->tt_msg->tt_tasks &= ~_tc->tc_task;
96a48c5dd5SSepherosa Ziehau 	_tp->tt_msg->tt_running_tasks &= ~_tc->tc_task;
97a48c5dd5SSepherosa Ziehau 	crit_exit();
98a48c5dd5SSepherosa Ziehau }
99a48c5dd5SSepherosa Ziehau 
100a48c5dd5SSepherosa Ziehau static __inline int
tcp_callout_active(struct tcpcb * _tp,struct tcp_callout * _tc)101a48c5dd5SSepherosa Ziehau tcp_callout_active(struct tcpcb *_tp, struct tcp_callout *_tc)
102a48c5dd5SSepherosa Ziehau {
103a48c5dd5SSepherosa Ziehau 	int _act;
104a48c5dd5SSepherosa Ziehau 
105e6f59cdaSSepherosa Ziehau 	KKASSERT(_tp->tt_msg->tt_cpuid == mycpuid);
106e6f59cdaSSepherosa Ziehau 
107a48c5dd5SSepherosa Ziehau 	crit_enter();
108a48c5dd5SSepherosa Ziehau 	_act = callout_active(&_tc->tc_callout);
1092d42d2b0SSepherosa Ziehau 	if (!_act) {
110a48c5dd5SSepherosa Ziehau 		_act = (_tp->tt_msg->tt_tasks |
111a48c5dd5SSepherosa Ziehau 			_tp->tt_msg->tt_running_tasks) & _tc->tc_task;
112a48c5dd5SSepherosa Ziehau 	}
113a48c5dd5SSepherosa Ziehau 	crit_exit();
114a48c5dd5SSepherosa Ziehau 	return _act;
115a48c5dd5SSepherosa Ziehau }
116a48c5dd5SSepherosa Ziehau 
117a48c5dd5SSepherosa Ziehau static __inline int
tcp_callout_pending(struct tcpcb * _tp,struct tcp_callout * _tc)118e6f59cdaSSepherosa Ziehau tcp_callout_pending(struct tcpcb *_tp, struct tcp_callout *_tc)
119a48c5dd5SSepherosa Ziehau {
120e6f59cdaSSepherosa Ziehau 	KKASSERT(_tp->tt_msg->tt_cpuid == mycpuid);
121e6f59cdaSSepherosa Ziehau 
122a48c5dd5SSepherosa Ziehau 	return callout_pending(&_tc->tc_callout);
123a48c5dd5SSepherosa Ziehau }
124a48c5dd5SSepherosa Ziehau 
125a48c5dd5SSepherosa Ziehau #endif	/* !_KERNEL */
126a48c5dd5SSepherosa Ziehau 
127a48c5dd5SSepherosa Ziehau #endif	/* _NETINET_TCP_TIMER2_H_ */
128