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 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef _GPXE_RETRY_H
  2. #define _GPXE_RETRY_H
  3. /** @file
  4. *
  5. * Retry timers
  6. *
  7. */
  8. #include <gpxe/list.h>
  9. /** Default timeout value */
  10. #define DEFAULT_MIN_TIMEOUT ( TICKS_PER_SEC / 4 )
  11. /** Limit after which the timeout will be deemed permanent */
  12. #define DEFAULT_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
  13. /** A retry timer */
  14. struct retry_timer {
  15. /** List of active timers */
  16. struct list_head list;
  17. /** Timer is currently running */
  18. unsigned int running;
  19. /** Timeout value (in ticks) */
  20. unsigned long timeout;
  21. /** Minimum timeout value (in ticks)
  22. *
  23. * A value of zero means "use default timeout."
  24. */
  25. unsigned long min_timeout;
  26. /** Maximum timeout value before failure (in ticks)
  27. *
  28. * A value of zero means "use default timeout."
  29. */
  30. unsigned long max_timeout;
  31. /** Start time (in ticks) */
  32. unsigned long start;
  33. /** Retry count */
  34. unsigned int count;
  35. /** Timer expired callback
  36. *
  37. * @v timer Retry timer
  38. * @v fail Failure indicator
  39. *
  40. * The timer will already be stopped when this method is
  41. * called. The failure indicator will be True if the retry
  42. * timeout has already exceeded @c MAX_TIMEOUT.
  43. */
  44. void ( * expired ) ( struct retry_timer *timer, int over );
  45. };
  46. extern void start_timer ( struct retry_timer *timer );
  47. extern void start_timer_fixed ( struct retry_timer *timer,
  48. unsigned long timeout );
  49. extern void stop_timer ( struct retry_timer *timer );
  50. /**
  51. * Start timer with no delay
  52. *
  53. * @v timer Retry timer
  54. *
  55. * This starts the timer running with a zero timeout value.
  56. */
  57. static inline void start_timer_nodelay ( struct retry_timer *timer ) {
  58. start_timer_fixed ( timer, 0 );
  59. }
  60. /**
  61. * Test to see if timer is currently running
  62. *
  63. * @v timer Retry timer
  64. * @ret running Non-zero if timer is running
  65. */
  66. static inline __attribute__ (( always_inline )) unsigned long
  67. timer_running ( struct retry_timer *timer ) {
  68. return ( timer->running );
  69. }
  70. #endif /* _GPXE_RETRY_H */