Debian Codegraph @

runtime/linux/timer_compatibility.h

raw
1 /*
2 * linux/timer.h compatibility defines and inlines
3 * Copyright (C) 2017 Red Hat Inc.
4 *
5 * This file is part of systemtap, and is free software. You can
6 * redistribute it and/or modify it under the terms of the GNU General
7 * Public License (GPL); either version 2, or (at your option) any
8 * later version.
9 */
10
11 #ifndef _TIMER_COMPATIBILITY_H_
12 #define _TIMER_COMPATIBILITY_H_
13
14 #include <linux/timer.h>
15
16 /*
17 * Starting with the 4.15 kernel, the timer interface
18 * changed. Originally, you'd do something like:
19 *
20 * static void timer_func(unsigned long val);
21 *
22 * init_timer(&timer);
23 * timer.expires = jiffies + STP_RELAY_TIMER_INTERVAL;
24 * timer.function = timer_func;
25 * timer.data = 0;
26 * add_timer(&timer);
27 *
28 * The 'data' parameter would get passed to the callback
29 * function. Starting with 4.15, you'd do something like this:
30 *
31 * static void timer_func(struct timer_list *val);
32 *
33 * timer_setup(&timer, timer_func, 0);
34 * timer.expires = jiffies + STP_RELAY_TIMER_INTERVAL;
35 * add_timer(&timer);
36 *
37 * With the new code, the timer that caused the callback gets passed
38 * to the timer callback function. The 'data' field has been removed.
39 *
40 * So, we're going to use the new interface. To hide the differences
41 * between the callback function parameter type, we'll define a new
42 * type, 'stp_timer_callback_parameter_t'.
43 *
44 * If code needs to figure out the difference between the old and new
45 * interface, it should test the init_timer define (which only exists
46 * in the old new interface).
47 */
48
49 #if !defined(init_timer)
50 /* This is the >= 4.15 kernel interface. */
51
52 typedef struct timer_list * stp_timer_callback_parameter_t;
53
54 #else
55 /* This is the < 4.15 kernel interface. */
56
57 typedef unsigned long stp_timer_callback_parameter_t;
58
59 /**
60 * timer_setup - prepare a timer for first use
61 * @timer: the timer in question
62 * @callback: the function to call when timer expires
63 * @flags: any TIMER_* flags (note that anything other than 0 is an
64 * error, since this compatibility function can't support any
65 * of the TIMER_* flags)
66 */
67 #define timer_setup(timer, callback, flags) \
68 { \
69 init_timer((timer)); \
70 (timer)->function = callback; \
71 (timer)->data = 0; \
72 BUILD_BUG_ON_ZERO((flags) != 0); \
73 }
74 #endif
75
76 #endif /* _TIMER_COMPATIBILITY_H_ */