summaryrefslogtreecommitdiffstats
path: root/src/include/gpxe/retry.h
blob: 71982fca5b8d426bd2395ec5de84d14e9494b1ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef _GPXE_RETRY_H
#define _GPXE_RETRY_H

/** @file
 *
 * Retry timers
 *
 */

#include <gpxe/list.h>

/** A retry timer */
struct retry_timer {
	/** List of active timers */
	struct list_head list;
	/** Timeout value (in ticks) */
	unsigned long timeout;
	/** Start time (in ticks)
	 *
	 * A start time of zero indicates a stopped timer.
	 */
	unsigned long start;
	/** Retry count */
	unsigned int count;
	/** Timer expired callback
	 *
	 * @v timer	Retry timer
	 * @v fail	Failure indicator
	 *
	 * The timer will already be stopped when this method is
	 * called.  The failure indicator will be True if the retry
	 * timeout has already exceeded @c MAX_TIMEOUT.
	 */
	void ( * expired ) ( struct retry_timer *timer, int over );
};

extern void start_timer ( struct retry_timer *timer );
extern void start_timer_fixed ( struct retry_timer *timer,
				unsigned long timeout );
extern void stop_timer ( struct retry_timer *timer );

/**
 * Start timer with no delay
 *
 * @v timer		Retry timer
 *
 * This starts the timer running with a zero timeout value.
 */
static inline void start_timer_nodelay ( struct retry_timer *timer ) {
	start_timer_fixed ( timer, 0 );
}

/**
 * Test to see if timer is currently running
 *
 * @v timer		Retry timer
 * @ret running		Non-zero if timer is running
 */
static inline __attribute__ (( always_inline )) unsigned long
timer_running ( struct retry_timer *timer ) {
	return ( timer->start );
}

#endif /* _GPXE_RETRY_H */