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
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_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 */
23 /** List of active timers */
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 */
70static inline __attribute__ (( always_inline )) void
71timer_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
87extern void start_timer ( struct retry_timer *timer );
88extern void start_timer_fixed ( struct retry_timer *timer,
89 unsigned long timeout );
90extern void stop_timer ( struct retry_timer *timer );
91extern 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 */
100static inline void start_timer_nodelay ( struct retry_timer *timer ) {
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 */
110static inline __attribute__ (( always_inline )) unsigned long
111timer_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 */
122static inline __attribute__ (( always_inline )) void
123set_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 */
#define min(x, y)
Definition ath.h:36
#define max(x, y)
Definition ath.h:41
void timeout(int)
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define __attribute__(x)
Definition compiler.h:10
Linked lists.
static void(* expired)(struct pooled_connection *pool)
Definition pool.h:62
void start_timer(struct retry_timer *timer)
Start timer.
Definition retry.c:94
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition retry.h:100
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition retry.c:65
void retry_poll(void)
Poll the retry timer list.
Definition retry.c:198
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition retry.c:118
A doubly-linked list entry (or list head)
Definition list.h:19
A reference counter.
Definition refcnt.h:27
A retry timer.
Definition retry.h:22
unsigned long timeout
Timeout value (in ticks)
Definition retry.h:28
unsigned int running
Timer is currently running.
Definition retry.h:26
unsigned long start
Start time (in ticks)
Definition retry.h:42
void(* expired)(struct retry_timer *timer, int over)
Timer expired callback.
Definition retry.h:54
unsigned long min
Minimum timeout value (in ticks), or zero to use default.
Definition retry.h:33
struct list_head list
List of active timers.
Definition retry.h:24
struct refcnt * refcnt
Reference counter.
Definition retry.h:60
unsigned long max
Maximum timeout value (in ticks), or zero to use default.
Definition retry.h:40
unsigned int count
Retry count.
Definition retry.h:44
A timer.
Definition timer.h:29