10 FILE_LICENCE ( GPL2_OR_LATER );
12 #include <ipxe/list.h>
14 /** Default timeout value */
15 #define DEFAULT_MIN_TIMEOUT ( TICKS_PER_SEC / 4 )
17 /** Limit after which the timeout will be deemed permanent */
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)
30 * A value of zero means "use default timeout."
32 unsigned long min_timeout;
33 /** Maximum timeout value before failure (in ticks)
35 * A value of zero means "use default timeout."
37 unsigned long max_timeout;
38 /** Start time (in ticks) */
42 /** Timer expired callback
44 * @v timer Retry timer
45 * @v fail Failure indicator
47 * The timer will already be stopped when this method is
48 * called. The failure indicator will be True if the retry
49 * timeout has already exceeded @c MAX_TIMEOUT.
51 void ( * expired ) ( struct retry_timer *timer, int over );
54 * If this interface is not part of a reference-counted
55 * object, this field may be NULL.
57 struct refcnt *refcnt;
63 * @v timer Retry timer
64 * @v expired Timer expired callback
65 * @v refcnt Reference counter, or NULL
67 static inline __attribute__ (( always_inline )) void
68 timer_init ( struct retry_timer *timer,
69 void ( * expired ) ( struct retry_timer *timer, int over ),
70 struct refcnt *refcnt ) {
71 timer->expired = expired;
72 timer->refcnt = refcnt;
76 * Initialise a static timer
78 * @v expired_fn Timer expired callback
80 #define TIMER_INIT( expired_fn ) { \
81 .expired = (expired_fn), \
84 extern void start_timer ( struct retry_timer *timer );
85 extern void start_timer_fixed ( struct retry_timer *timer,
86 unsigned long timeout );
87 extern void stop_timer ( struct retry_timer *timer );
88 extern void retry_poll ( void );
91 * Start timer with no delay
93 * @v timer Retry timer
95 * This starts the timer running with a zero timeout value.
97 static inline void start_timer_nodelay ( struct retry_timer *timer ) {
98 start_timer_fixed ( timer, 0 );
102 * Test to see if timer is currently running
104 * @v timer Retry timer
105 * @ret running Non-zero if timer is running
107 static inline __attribute__ (( always_inline )) unsigned long
108 timer_running ( struct retry_timer *timer ) {
109 return ( timer->running );
112 #endif /* _IPXE_RETRY_H */