backoff.h 596 Bytes
Newer Older
1 2 3
#ifndef _BACKOFF_H_
#define _BACKOFF_H_

4
#include <time.h>
5 6

struct backoff {
7 8 9
  struct timespec max;
  struct timespec min;
  struct timespec sleep;
10 11 12
};

/* Initialize a backoff struct with a max value */
13
void backoff_init(struct backoff *b, struct timespec *min, struct timespec *max);
14 15 16 17 18 19 20 21 22

/* Execute a backoff. This will sleep for a time.
 * The next backoff() call will sleep twice as long (or the max value,
 * whichever is smaller) */
void backoff(struct backoff *b);

/* Reset the next backoff() call to sleep the minimum (1ms) */
void backoff_clear(struct backoff *b);
#endif /* _BACKOFF_H_ */