CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
backoff.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_BACKOFF_H_
6 #define CVMFS_BACKOFF_H_
7 
8 #include <pthread.h>
9 
10 #include "prng.h"
11 #include "util/single_copy.h"
12 
18 class BackoffThrottle : public SingleCopy {
19  public:
20  static const unsigned kDefaultInitDelay = 32;
21  static const unsigned kDefaultMaxDelay = 2000;
25  static const unsigned kDefaultResetAfter = 10000;
26 
29  }
30  BackoffThrottle(const unsigned init_delay_ms,
31  const unsigned max_delay_ms,
32  const unsigned reset_after_ms)
33  {
34  Init(init_delay_ms, max_delay_ms, reset_after_ms);
35  }
37  void Throttle();
38  void Reset();
39 
40  private:
41  void Init(const unsigned init_delay_ms,
42  const unsigned max_delay_ms,
43  const unsigned reset_after_ms);
44  unsigned delay_range_;
45  unsigned init_delay_ms_;
46  unsigned max_delay_ms_;
47  unsigned reset_after_ms_;
50  pthread_mutex_t *lock_;
51 };
52 
53 #endif // CVMFS_BACKOFF_H_
Definition: prng.h:25
static const unsigned kDefaultMaxDelay
Definition: backoff.h:21
void Init(const unsigned init_delay_ms, const unsigned max_delay_ms, const unsigned reset_after_ms)
Definition: backoff.cc:18
static const unsigned kDefaultInitDelay
Definition: backoff.h:20
BackoffThrottle(const unsigned init_delay_ms, const unsigned max_delay_ms, const unsigned reset_after_ms)
Definition: backoff.h:30
static const unsigned kDefaultResetAfter
Definition: backoff.h:25
void Throttle()
Definition: backoff.cc:50
time_t last_throttle_
Definition: backoff.h:48
unsigned delay_range_
Definition: backoff.h:44
pthread_mutex_t * lock_
Definition: backoff.h:50
unsigned init_delay_ms_
Definition: backoff.h:45
void Reset()
Definition: backoff.cc:42
unsigned reset_after_ms_
Definition: backoff.h:47
unsigned max_delay_ms_
Definition: backoff.h:46