xref: /haiku/src/libs/compat/freebsd_network/compat/sys/callout.h (revision e9c4d47ad719d6fd67cd9b75b41ebbec563e7a79)
1 /*
2  * Copyright 2007, Hugo Santos. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _FBSD_COMPAT_SYS_CALLOUT_H_
6 #define _FBSD_COMPAT_SYS_CALLOUT_H_
7 
8 #include <sys/haiku-module.h>
9 
10 #include <sys/mutex.h>
11 #include <sys/queue.h>
12 
13 
14 struct callout {
15 	struct net_timer	c_timer;
16 	void *				c_arg;
17 	void				(*c_func)(void *);
18 	struct mtx *		c_mtx;
19 	int					c_flags;
20 };
21 
22 #define CALLOUT_MPSAFE	0x0001
23 
24 void callout_init_mtx(struct callout *c, struct mtx *mutex, int flags);
25 int	callout_reset(struct callout *c, int, void (*func)(void *), void *arg);
26 int callout_pending(struct callout *c);
27 int callout_active(struct callout *c);
28 
29 #define	callout_drain(c)	_callout_stop_safe(c, 1)
30 #define	callout_stop(c)		_callout_stop_safe(c, 0)
31 int	_callout_stop_safe(struct callout *, int);
32 
33 
34 static inline void
35 callout_init(struct callout *c, int mpsafe)
36 {
37 	if (mpsafe)
38 		callout_init_mtx(c, NULL, 0);
39 	else
40 		callout_init_mtx(c, &Giant, 0);
41 }
42 
43 #endif	/* _FBSD_COMPAT_SYS_CALLOUT_H_ */
44