Skip to content

Commit 86de63a

Browse files
Some refactor
1 parent 4ceb077 commit 86de63a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Include/internal/pycore_backoff.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ extern "C" {
3232
*/
3333

3434
#define BACKOFF_BITS 4
35+
#define BACKOFF_MASK 0xF
3536
#define MAX_BACKOFF 12
3637
#define UNREACHABLE_BACKOFF 15
38+
#define MAX_VALUE 0xFFF
3739

3840
static inline bool
3941
is_unreachable_backoff_counter(_Py_BackoffCounter counter)
@@ -44,8 +46,8 @@ is_unreachable_backoff_counter(_Py_BackoffCounter counter)
4446
static inline _Py_BackoffCounter
4547
make_backoff_counter(uint16_t value, uint16_t backoff)
4648
{
47-
assert(backoff <= 15);
48-
assert(value <= 0xFFF);
49+
assert(backoff <= UNREACHABLE_BACKOFF);
50+
assert(value <= MAX_VALUE);
4951
_Py_BackoffCounter result;
5052
result.value_and_backoff = (value << BACKOFF_BITS) | backoff;
5153
return result;
@@ -63,7 +65,7 @@ static inline _Py_BackoffCounter
6365
restart_backoff_counter(_Py_BackoffCounter counter)
6466
{
6567
assert(!is_unreachable_backoff_counter(counter));
66-
int backoff = counter.value_and_backoff & 15;
68+
int backoff = counter.value_and_backoff & BACKOFF_MASK;
6769
if (backoff < MAX_BACKOFF) {
6870
return make_backoff_counter((1 << (backoff + 1)) - 1, backoff + 1);
6971
}

0 commit comments

Comments
 (0)