4 #define CALLOUT_ACTIVE 0x0002 /* callout is currently active */
5 #define CALLOUT_MPSAFE 0x0008 /* callout handler is mp safe */
7 #ifndef _WIN32 /* this is the linux version */
8 /* callout support, in <sys/callout.h> on FreeBSD */
10 * callout support on linux module is done using timers
12 #include <linux/timer.h>
14 #include <linux/sched.h> /* jiffies definition is here in 2.4 */
16 #define callout timer_list
18 callout_reset(struct callout *co, int ticks, void (*fn)(void *), void *arg)
20 co->expires = jiffies + ticks;
21 co->function = (void (*)(unsigned long))fn;
22 co->data = (unsigned long)arg;
27 #define callout_init(co, safe) init_timer(co)
28 #define callout_drain(co) del_timer(co)
29 #define callout_stop(co) del_timer(co)
34 /* This is the windows part for callout support */
39 LARGE_INTEGER duetime;
42 void dummynet (void*);
44 __in struct _KDPC *Dpc,
45 __in_opt PVOID DeferredContext,
46 __in_opt PVOID SystemArgument1,
47 __in_opt PVOID SystemArgument2
51 __in struct _KDPC *Dpc,
52 __in_opt PVOID DeferredContext,
53 __in_opt PVOID SystemArgument1,
54 __in_opt PVOID SystemArgument2
57 /* callout_reset must handle two problems:
58 * - dummynet() scheduler must be run always on the same processor
59 * because do_gettimeofday() is based on cpu performance counter, and
60 * _occasionally_ can leap backward in time if we query another cpu.
61 * typically this won't happen that much, and the cpu will almost always
62 * be the same even without the affinity restriction, but better to be sure.
63 * - ipfw_tick() does not have the granularity requirements of dummynet()
64 * but we need to pass a pointer as argument.
66 * for these reasons, if we are called for dummynet() timer,
67 * KeInitializeDpc is called only once as it should be, and the thread
68 * is forced on cpu0 (which is always present), while if we're called
69 * for ipfw_tick(), we re-initialize the DPC each time, using
70 * parameter DeferredContext to pass the needed pointer. since this
71 * timer is called only once a sec, this won't hurt that much.
74 callout_reset(struct callout *co, int ticks, void (*fn)(void *), void *arg)
78 if(co->dpcinitialized == 0)
80 KeInitializeDpc(&co->timerdpc, dummynet_dpc, NULL);
81 KeSetTargetProcessorDpc(&co->timerdpc, 0);
82 co->dpcinitialized = 1;
87 KeInitializeDpc(&co->timerdpc, ipfw_dpc, arg);
89 co->duetime.QuadPart = (-ticks)*10000;
90 KeSetTimer(&co->thetimer, co->duetime, &co->timerdpc);
95 callout_init(struct callout* co, int safe)
97 printf("%s: initializing timer at %p\n",__FUNCTION__,co);
98 KeInitializeTimer(&co->thetimer);
102 callout_drain(struct callout* co)
104 BOOLEAN canceled = KeCancelTimer(&co->thetimer);
105 while (canceled != TRUE)
107 canceled = KeCancelTimer(&co->thetimer);
109 printf("%s: stopping timer at %p\n",__FUNCTION__,co);
114 callout_stop(struct callout* co)
116 return callout_drain(co);
121 #endif /* _SYS_SYSTM_H_ */