-
Notifications
You must be signed in to change notification settings - Fork 0
/
backoff.c
47 lines (41 loc) · 983 Bytes
/
backoff.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "test.h"
void backoff_init()
{
int i;
for (i = 0; i < MAX_THREADS + 1; i++) {
get_thread(i)->backoff_amount = 1;
}
}
void backoff_reset()
{
/* We want the initial backoff amount to be half what we had last
* time. Since the first thing backoff_delay() does is double
* the backoff amount, we divide by four.
*/
int x = this_thread()->backoff_amount;
x >>= 2;
if (x == 0) {
x = 1;
}
this_thread()->backoff_amount = x;
}
long backoff_delay()
{
#ifdef USE_BACKOFF
int i;
long j;
/* Double the backoff amount if doing so doesn't make us exceed
* our limits. */
this_thread()->backoff_amount <<= 2;
while (this_thread()->backoff_amount > tg->nthreads) {
this_thread()->backoff_amount >>= 2;
}
for (i = 0; i < this_thread()->backoff_amount; i++) {
j = j * i;
}
if (j == this_thread()->backoff_amount) {
return j;
}
#endif
return 0;
}