iPXE
retry.h
Go to the documentation of this file.
1 #ifndef _IPXE_RETRY_H
2 #define _IPXE_RETRY_H
3 
4 /** @file
5  *
6  * Retry timers
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <ipxe/list.h>
13 
14 /** Default minimum timeout value (in ticks) */
15 #define DEFAULT_MIN_TIMEOUT ( TICKS_PER_SEC / 4 )
16 
17 /** Default maximum timeout value (in ticks) */
18 #define DEFAULT_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
19 
20 /** A retry timer */
21 struct retry_timer {
22  /** List of active timers */
23  struct list_head list;
24  /** Timer is currently running */
25  unsigned int running;
26  /** Timeout value (in ticks) */
27  unsigned long timeout;
28  /** Minimum timeout value (in ticks), or zero to use default
29  *
30  * The timeout will never be reduced below this value.
31  */
32  unsigned long min;
33  /** Maximum timeout value (in ticks), or zero to use default
34  *
35  * The timeout will be deemed permanent (according to the
36  * failure indicator passed to expired()) when it exceeds this
37  * value.
38  */
39  unsigned long max;
40  /** Start time (in ticks) */
41  unsigned long start;
42  /** Retry count */
43  unsigned int count;
44  /** Timer expired callback
45  *
46  * @v timer Retry timer
47  * @v fail Failure indicator
48  *
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.
52  */
53  void ( * expired ) ( struct retry_timer *timer, int over );
54  /** Reference counter
55  *
56  * If this interface is not part of a reference-counted
57  * object, this field may be NULL.
58  */
59  struct refcnt *refcnt;
60 };
61 
62 /**
63  * Initialise a timer
64  *
65  * @v timer Retry timer
66  * @v expired Timer expired callback
67  * @v refcnt Reference counter, or NULL
68  */
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;
75 }
76 
77 /**
78  * Initialise a static timer
79  *
80  * @v expired_fn Timer expired callback
81  */
82 #define TIMER_INIT( expired_fn ) { \
83  .expired = (expired_fn), \
84  }
85 
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 );
91 
92 /**
93  * Start timer with no delay
94  *
95  * @v timer Retry timer
96  *
97  * This starts the timer running with a zero timeout value.
98  */
99 static inline void start_timer_nodelay ( struct retry_timer *timer ) {
100  start_timer_fixed ( timer, 0 );
101 }
102 
103 /**
104  * Test to see if timer is currently running
105  *
106  * @v timer Retry timer
107  * @ret running Non-zero if timer is running
108  */
109 static inline __attribute__ (( always_inline )) unsigned long
110 timer_running ( struct retry_timer *timer ) {
111  return ( timer->running );
112 }
113 
114 /**
115  * Set minimum and maximum timeouts
116  *
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
120  */
121 static inline __attribute__ (( always_inline )) void
122 set_timer_limits ( struct retry_timer *timer, unsigned long min,
123  unsigned long max ) {
124  timer->min = min;
125  timer->max = max;
126 }
127 
128 #endif /* _IPXE_RETRY_H */
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
struct list_head list
List of active timers.
Definition: retry.h:23
A retry timer.
Definition: retry.h:21
static unsigned long unsigned long max
Definition: retry.h:123
void(* expired)(struct retry_timer *timer, int over)
Timer expired callback.
Definition: retry.h:53
unsigned long start
Start time (in ticks)
Definition: retry.h:41
A doubly-linked list entry (or list head)
Definition: list.h:18
A reference counter.
Definition: refcnt.h:26
A timer.
Definition: timer.h:28
static unsigned long min
Definition: retry.h:122
struct refcnt * refcnt
Reference counter.
Definition: retry.h:59
Linked lists.
void retry_poll(void)
Poll the retry timer list.
Definition: retry.c:197
static void(*) struct refcnt refcnt)
Definition: retry.h:72
static __attribute__((always_inline)) void timer_init(struct retry_timer *timer
Initialise a timer.
Definition: retry.h:109
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
static void(* expired)(struct retry_timer *timer, int over)
Definition: retry.h:71
unsigned int count
Retry count.
Definition: retry.h:43
unsigned long max
Maximum timeout value (in ticks), or zero to use default.
Definition: retry.h:39
static struct timer * timer
Current timer.
Definition: timer.c:35
unsigned long min
Minimum timeout value (in ticks), or zero to use default.
Definition: retry.h:32
void start_timer(struct retry_timer *timer)
Start timer.
Definition: retry.c:93
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition: retry.c:64
unsigned int running
Timer is currently running.
Definition: retry.h:25
void timeout(int)
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
unsigned long timeout
Timeout value (in ticks)
Definition: retry.h:27