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