You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

retry.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef _IPXE_RETRY_H
  2. #define _IPXE_RETRY_H
  3. /** @file
  4. *
  5. * Retry timers
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <ipxe/list.h>
  10. /** Default timeout value */
  11. #define DEFAULT_MIN_TIMEOUT ( TICKS_PER_SEC / 4 )
  12. /** Limit after which the timeout will be deemed permanent */
  13. #define DEFAULT_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
  14. /** A retry timer */
  15. struct retry_timer {
  16. /** List of active timers */
  17. struct list_head list;
  18. /** Timer is currently running */
  19. unsigned int running;
  20. /** Timeout value (in ticks) */
  21. unsigned long timeout;
  22. /** Minimum timeout value (in ticks)
  23. *
  24. * A value of zero means "use default timeout."
  25. */
  26. unsigned long min_timeout;
  27. /** Maximum timeout value before failure (in ticks)
  28. *
  29. * A value of zero means "use default timeout."
  30. */
  31. unsigned long max_timeout;
  32. /** Start time (in ticks) */
  33. unsigned long start;
  34. /** Retry count */
  35. unsigned int count;
  36. /** Timer expired callback
  37. *
  38. * @v timer Retry timer
  39. * @v fail Failure indicator
  40. *
  41. * The timer will already be stopped when this method is
  42. * called. The failure indicator will be True if the retry
  43. * timeout has already exceeded @c MAX_TIMEOUT.
  44. */
  45. void ( * expired ) ( struct retry_timer *timer, int over );
  46. /** Reference counter
  47. *
  48. * If this interface is not part of a reference-counted
  49. * object, this field may be NULL.
  50. */
  51. struct refcnt *refcnt;
  52. };
  53. /**
  54. * Initialise a timer
  55. *
  56. * @v timer Retry timer
  57. * @v expired Timer expired callback
  58. * @v refcnt Reference counter, or NULL
  59. */
  60. static inline __attribute__ (( always_inline )) void
  61. timer_init ( struct retry_timer *timer,
  62. void ( * expired ) ( struct retry_timer *timer, int over ),
  63. struct refcnt *refcnt ) {
  64. timer->expired = expired;
  65. timer->refcnt = refcnt;
  66. }
  67. /**
  68. * Initialise a static timer
  69. *
  70. * @v expired_fn Timer expired callback
  71. */
  72. #define TIMER_INIT( expired_fn ) { \
  73. .expired = (expired_fn), \
  74. }
  75. extern void start_timer ( struct retry_timer *timer );
  76. extern void start_timer_fixed ( struct retry_timer *timer,
  77. unsigned long timeout );
  78. extern void stop_timer ( struct retry_timer *timer );
  79. extern void retry_poll ( void );
  80. /**
  81. * Start timer with no delay
  82. *
  83. * @v timer Retry timer
  84. *
  85. * This starts the timer running with a zero timeout value.
  86. */
  87. static inline void start_timer_nodelay ( struct retry_timer *timer ) {
  88. start_timer_fixed ( timer, 0 );
  89. }
  90. /**
  91. * Test to see if timer is currently running
  92. *
  93. * @v timer Retry timer
  94. * @ret running Non-zero if timer is running
  95. */
  96. static inline __attribute__ (( always_inline )) unsigned long
  97. timer_running ( struct retry_timer *timer ) {
  98. return ( timer->running );
  99. }
  100. #endif /* _IPXE_RETRY_H */