Skip to content

Commit dda4cdb

Browse files
Review addressed: change values and comment
1 parent 5b7bfd9 commit dda4cdb

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Include/internal/pycore_backoff.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ extern "C" {
2525
The 16-bit counter is structured as a 13-bit unsigned 'value'
2626
and a 3-bit 'backoff' field. When resetting the counter, the
2727
backoff field is incremented (until it reaches a limit) and the
28-
value is set to a bit mask representing some prime value near
29-
to 2**(2*backoff+1) - 1, see value_and_backoff_next.
28+
value is set to a bit mask representing some prime value - 1.
29+
New values and backoffs for each backoff are calculated once
30+
at compile time and saved to value_and_backoff_next table.
3031
The maximum backoff is 6, since 7 is an UNREACHABLE_BACKOFF.
3132
3233
There is an exceptional value which must not be updated, 0xFFFF.
@@ -41,15 +42,15 @@ extern "C" {
4142
#define MAKE_VALUE_AND_BACKOFF(value, backoff) \
4243
((value << BACKOFF_BITS) | backoff)
4344

44-
// We only use values x and backoffs b such that
45+
// For previous backoff b we use value x such that
4546
// x + 1 is near to 2**(2*b+1) and x + 1 is prime.
4647
static const uint16_t value_and_backoff_next[] = {
47-
MAKE_VALUE_AND_BACKOFF(6, 1),
48-
MAKE_VALUE_AND_BACKOFF(30, 2),
49-
MAKE_VALUE_AND_BACKOFF(126, 3),
50-
MAKE_VALUE_AND_BACKOFF(508, 4),
51-
MAKE_VALUE_AND_BACKOFF(2052, 5),
52-
MAKE_VALUE_AND_BACKOFF(8190, 6),
48+
MAKE_VALUE_AND_BACKOFF(1, 1),
49+
MAKE_VALUE_AND_BACKOFF(6, 2),
50+
MAKE_VALUE_AND_BACKOFF(30, 3),
51+
MAKE_VALUE_AND_BACKOFF(126, 4),
52+
MAKE_VALUE_AND_BACKOFF(508, 5),
53+
MAKE_VALUE_AND_BACKOFF(2052, 6),
5354
// We use the same backoff counter for all backoffs >= MAX_BACKOFF.
5455
MAKE_VALUE_AND_BACKOFF(8190, 6),
5556
MAKE_VALUE_AND_BACKOFF(8190, 6),

0 commit comments

Comments
 (0)