10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12 #include <ipxe/list.h>
14 /** Default minimum timeout value (in ticks) */
15 #define DEFAULT_MIN_TIMEOUT ( TICKS_PER_SEC / 4 )
17 /** Default maximum timeout value (in ticks) */
18 #define DEFAULT_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
22 /** List of active timers */
23 struct list_head list;
24 /** Timer is currently running */
26 /** Timeout value (in ticks) */
27 unsigned long timeout;
28 /** Minimum timeout value (in ticks), or zero to use default
30 * The timeout will never be reduced below this value.
33 /** Maximum timeout value (in ticks), or zero to use default
35 * The timeout will be deemed permanent (according to the
36 * failure indicator passed to expired()) when it exceeds this
40 /** Start time (in ticks) */
44 /** Timer expired callback
46 * @v timer Retry timer
47 * @v fail Failure indicator
49 * The timer will already be stopped when this method is
50 * called. The failure indicator will be True if the retry
51 * timeout has already exceeded @c max_timeout.
53 void ( * expired ) ( struct retry_timer *timer, int over );
56 * If this interface is not part of a reference-counted
57 * object, this field may be NULL.
59 struct refcnt *refcnt;
65 * @v timer Retry timer
66 * @v expired Timer expired callback
67 * @v refcnt Reference counter, or NULL
69 static inline __attribute__ (( always_inline )) void
70 timer_init ( struct retry_timer *timer,
71 void ( * expired ) ( struct retry_timer *timer, int over ),
72 struct refcnt *refcnt ) {
73 timer->expired = expired;
74 timer->refcnt = refcnt;
78 * Initialise a static timer
80 * @v expired_fn Timer expired callback
82 #define TIMER_INIT( expired_fn ) { \
83 .expired = (expired_fn), \
86 extern void start_timer ( struct retry_timer *timer );
87 extern void start_timer_fixed ( struct retry_timer *timer,
88 unsigned long timeout );
89 extern void stop_timer ( struct retry_timer *timer );
90 extern void retry_poll ( void );
93 * Start timer with no delay
95 * @v timer Retry timer
97 * This starts the timer running with a zero timeout value.
99 static inline void start_timer_nodelay ( struct retry_timer *timer ) {
100 start_timer_fixed ( timer, 0 );
104 * Test to see if timer is currently running
106 * @v timer Retry timer
107 * @ret running Non-zero if timer is running
109 static inline __attribute__ (( always_inline )) unsigned long
110 timer_running ( struct retry_timer *timer ) {
111 return ( timer->running );
115 * Set minimum and maximum timeouts
117 * @v timer Retry timer
118 * @v min Minimum timeout (in ticks), or zero to use default
119 * @v max Maximum timeout (in ticks), or zero to use default
121 static inline __attribute__ (( always_inline )) void
122 set_timer_limits ( struct retry_timer *timer, unsigned long min,
123 unsigned long max ) {
128 #endif /* _IPXE_RETRY_H */