2010-04-19 21:16:01 +02:00
|
|
|
#ifndef _IPXE_RETRY_H
|
|
|
|
#define _IPXE_RETRY_H
|
2006-05-29 16:55:07 +02:00
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* Retry timers
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-05-01 16:41:06 +02:00
|
|
|
FILE_LICENCE ( GPL2_OR_LATER );
|
|
|
|
|
2010-04-19 21:16:01 +02:00
|
|
|
#include <ipxe/list.h>
|
2006-05-29 16:55:07 +02:00
|
|
|
|
2008-08-12 02:05:26 +02:00
|
|
|
/** Default timeout value */
|
|
|
|
#define DEFAULT_MIN_TIMEOUT ( TICKS_PER_SEC / 4 )
|
|
|
|
|
|
|
|
/** Limit after which the timeout will be deemed permanent */
|
|
|
|
#define DEFAULT_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
|
|
|
|
|
2006-05-29 16:55:07 +02:00
|
|
|
/** A retry timer */
|
|
|
|
struct retry_timer {
|
|
|
|
/** List of active timers */
|
|
|
|
struct list_head list;
|
2008-10-12 16:04:37 +02:00
|
|
|
/** Timer is currently running */
|
|
|
|
unsigned int running;
|
2006-06-01 16:33:52 +02:00
|
|
|
/** Timeout value (in ticks) */
|
|
|
|
unsigned long timeout;
|
2008-08-12 02:05:26 +02:00
|
|
|
/** Minimum timeout value (in ticks)
|
|
|
|
*
|
|
|
|
* A value of zero means "use default timeout."
|
|
|
|
*/
|
|
|
|
unsigned long min_timeout;
|
|
|
|
/** Maximum timeout value before failure (in ticks)
|
|
|
|
*
|
|
|
|
* A value of zero means "use default timeout."
|
|
|
|
*/
|
|
|
|
unsigned long max_timeout;
|
2008-10-12 16:04:37 +02:00
|
|
|
/** Start time (in ticks) */
|
2006-06-01 16:33:52 +02:00
|
|
|
unsigned long start;
|
2006-08-09 17:54:17 +02:00
|
|
|
/** Retry count */
|
|
|
|
unsigned int count;
|
2006-05-29 16:55:07 +02:00
|
|
|
/** Timer expired callback
|
|
|
|
*
|
|
|
|
* @v timer Retry timer
|
2006-06-01 16:33:52 +02:00
|
|
|
* @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.
|
2006-05-29 16:55:07 +02:00
|
|
|
*/
|
2006-06-01 16:33:52 +02:00
|
|
|
void ( * expired ) ( struct retry_timer *timer, int over );
|
2006-05-29 16:55:07 +02:00
|
|
|
};
|
|
|
|
|
2010-06-15 19:13:36 +02:00
|
|
|
/**
|
|
|
|
* Initialise a timer
|
|
|
|
*
|
|
|
|
* @v timer Retry timer
|
|
|
|
* @v expired Timer expired callback
|
|
|
|
*/
|
|
|
|
static inline __attribute__ (( always_inline )) void
|
|
|
|
timer_init ( struct retry_timer *timer,
|
|
|
|
void ( * expired ) ( struct retry_timer *timer, int over ) ) {
|
|
|
|
timer->expired = expired;
|
|
|
|
}
|
|
|
|
|
2006-05-29 16:55:07 +02:00
|
|
|
extern void start_timer ( struct retry_timer *timer );
|
2008-06-11 10:37:58 +02:00
|
|
|
extern void start_timer_fixed ( struct retry_timer *timer,
|
|
|
|
unsigned long timeout );
|
2006-05-29 16:55:07 +02:00
|
|
|
extern void stop_timer ( struct retry_timer *timer );
|
|
|
|
|
2008-06-11 10:37:58 +02:00
|
|
|
/**
|
|
|
|
* 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 );
|
|
|
|
}
|
|
|
|
|
2007-05-26 17:00:56 +02:00
|
|
|
/**
|
|
|
|
* 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 ) {
|
2008-10-12 16:04:37 +02:00
|
|
|
return ( timer->running );
|
2007-05-26 17:00:56 +02:00
|
|
|
}
|
|
|
|
|
2010-04-19 21:16:01 +02:00
|
|
|
#endif /* _IPXE_RETRY_H */
|